mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:17:01 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=false was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (1062 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(lint): reattach two guards the reformat detached Both effects were one-liners, so a trailing eslint-disable-line covered the setState call: useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ... prettier expanded the block. The comment stayed on the closing line while the call moved above it, so the guard protected nothing and the rule its author had deliberately silenced failed the build. This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line variant. Both come from the same fact: an eslint directive binds to a line number, so reformatting can silently unbind it, which makes 'mechanical, no behaviour change' false for any bulk reformat. * chore(desktop): bump the runner version the reformat requires desktop-release-drift enforces that anything built into Fleet Runner which differs from the last released tag must carry a version ahead of that tag — main read 0.8.15 and fleet-runner-v0.8.15 already shipped. A whole-repo reformat changes bytes under desktop/, so the gate fires. The alternative was adding desktop/ to .prettierignore, which would buy a quiet PR by carving a permanent hole in the formatter's coverage — the precise shape of silent drift this test was written to catch. Bumping is what the rule asks for and costs one patch release whose only content is whitespace. * chore: merge main and re-format A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR runs no checks at all while reporting nothing. Conflicts resolved to main, which is correct because this branch changes formatting and nothing else. * chore: leave desktop/ out of this reformat desktop-release-drift is right to refuse this. Everything under desktop/ is built into Fleet Runner, so changing it means shipping: bump the version AND add a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed Fleet Runner and wants to know what changed'. For a whitespace-only build the honest answer is 'nothing', so that release should not exist — and I should not write release notes claiming otherwise. I had bumped to 0.8.16 to get the gate green. That was the wrong direction: publishing a build to three OS runners to keep a formatting PR quiet. Reverted. desktop/ is excluded in .prettierignore with the reasoning recorded there, to be formatted alongside the next real runner change, where the bump and the notes are true anyway. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
380 lines
13 KiB
JavaScript
380 lines
13 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { chromium } from "playwright";
|
|
|
|
const root = process.cwd();
|
|
const outDir = path.join(root, ".tmp", "projects-tour");
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
|
|
function readLocalEnv() {
|
|
const envPath = path.join(root, ".env.local");
|
|
if (!fs.existsSync(envPath)) return;
|
|
for (const line of fs.readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const idx = trimmed.indexOf("=");
|
|
if (idx === -1) continue;
|
|
const key = trimmed.slice(0, idx);
|
|
const value = trimmed.slice(idx + 1).replace(/^"|"$/g, "");
|
|
if (!process.env[key]) process.env[key] = value;
|
|
}
|
|
}
|
|
|
|
readLocalEnv();
|
|
|
|
const base = process.env.BASE ?? "http://127.0.0.1:3001";
|
|
const ownerPassword = process.env.LOCAL_AUTH_PASSWORD;
|
|
const dogfoodEmail = process.env.DOGFOOD_EMAIL;
|
|
const dogfoodPassword = process.env.DOGFOOD_PASSWORD;
|
|
const isLocal = base.includes("localhost") || base.includes("127.0.0.1");
|
|
|
|
const allViewports = [
|
|
{ tag: "mobile-320", width: 320, height: 700, isMobile: true },
|
|
{ tag: "mobile-390", width: 390, height: 844, isMobile: true },
|
|
{ tag: "tablet", width: 768, height: 1024, isMobile: false },
|
|
{ tag: "desktop", width: 1440, height: 1000, isMobile: false },
|
|
];
|
|
const requestedViewports = new Set(
|
|
(process.env.VIEWPORTS ?? "")
|
|
.split(",")
|
|
.map((value) => value.trim())
|
|
.filter(Boolean),
|
|
);
|
|
const viewports = requestedViewports.size
|
|
? allViewports.filter((viewport) => requestedViewports.has(viewport.tag))
|
|
: allViewports;
|
|
|
|
function check(condition, message) {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
async function login(page) {
|
|
await page.goto(`${base}/sign-in?callbackUrl=/projects`, { waitUntil: "domcontentloaded" });
|
|
if (isLocal) {
|
|
const ownerTab = page.getByRole("button", { name: /owner key/i });
|
|
await ownerTab.waitFor({ state: "visible", timeout: 30_000 });
|
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
await ownerTab.click();
|
|
if (await page.locator("#owner-password").isVisible()) break;
|
|
await page.waitForTimeout(500);
|
|
}
|
|
if (!ownerPassword) throw new Error("LOCAL_AUTH_PASSWORD is not configured");
|
|
await page.locator("#owner-password").fill(ownerPassword);
|
|
await page.getByRole("button", { name: /sign in as owner/i }).click();
|
|
} else {
|
|
if (!dogfoodEmail || !dogfoodPassword) {
|
|
throw new Error("DOGFOOD_EMAIL and DOGFOOD_PASSWORD are required for a production tour");
|
|
}
|
|
await page.locator('input[type="email"]').first().fill(dogfoodEmail);
|
|
await page.locator('input[type="password"]').first().fill(dogfoodPassword);
|
|
await page
|
|
.getByRole("button", { name: /^sign in/i })
|
|
.last()
|
|
.click();
|
|
}
|
|
await page.waitForURL((url) => !url.pathname.startsWith("/sign-in"), { timeout: 60_000 });
|
|
}
|
|
|
|
async function auditLayout(page, viewport) {
|
|
return page.evaluate(({ width, isMobile }) => {
|
|
const visible = (el) => {
|
|
const style = getComputedStyle(el);
|
|
const rect = el.getBoundingClientRect();
|
|
return (
|
|
rect.width > 0 &&
|
|
rect.height > 0 &&
|
|
style.display !== "none" &&
|
|
style.visibility !== "hidden"
|
|
);
|
|
};
|
|
const elements = [...document.querySelectorAll("body *")];
|
|
const overflow = elements
|
|
.filter(visible)
|
|
.map((el) => {
|
|
const rect = el.getBoundingClientRect();
|
|
return {
|
|
tag: el.tagName.toLowerCase(),
|
|
text: (el.textContent || "").trim().replace(/\s+/g, " ").slice(0, 80),
|
|
cls: typeof el.className === "string" ? el.className.slice(0, 100) : "",
|
|
left: Math.round(rect.left),
|
|
right: Math.round(rect.right),
|
|
};
|
|
})
|
|
.filter((item) => item.left < -2 || item.right > width + 2)
|
|
.slice(0, 20);
|
|
const smallTargets = isMobile
|
|
? elements
|
|
.filter(
|
|
(el) => el.matches("a,button,input,select,textarea,[role='button']") && visible(el),
|
|
)
|
|
.map((el) => {
|
|
const target =
|
|
el.matches('input[type="checkbox"], input[type="radio"]') && el.closest("label")
|
|
? el.closest("label")
|
|
: el;
|
|
const rect = target.getBoundingClientRect();
|
|
return {
|
|
text: (
|
|
el.getAttribute("aria-label") ||
|
|
el.textContent ||
|
|
el.getAttribute("title") ||
|
|
""
|
|
)
|
|
.trim()
|
|
.replace(/\s+/g, " ")
|
|
.slice(0, 80),
|
|
width: Math.round(rect.width),
|
|
height: Math.round(rect.height),
|
|
};
|
|
})
|
|
.filter((item) => item.width < 36 || item.height < 36)
|
|
.slice(0, 30)
|
|
: [];
|
|
const tinyText = elements
|
|
.filter(visible)
|
|
.map((el) => ({
|
|
text: (el.textContent || "").trim().replace(/\s+/g, " ").slice(0, 80),
|
|
size: Number.parseFloat(getComputedStyle(el).fontSize),
|
|
}))
|
|
.filter((item) => item.text && item.size > 0 && item.size < (isMobile ? 12 : 11))
|
|
.slice(0, 30);
|
|
|
|
return {
|
|
path: location.pathname,
|
|
query: location.search,
|
|
title: document.title,
|
|
clientWidth: document.documentElement.clientWidth,
|
|
scrollWidth: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
|
|
overflow,
|
|
smallTargets,
|
|
tinyText,
|
|
};
|
|
}, viewport);
|
|
}
|
|
|
|
async function waitForCatalog(page) {
|
|
await page.waitForSelector('a[href^="/projects/"]', { timeout: 30_000 });
|
|
}
|
|
|
|
async function auditCatalog(page, viewport) {
|
|
const layout = await auditLayout(page, viewport);
|
|
const content = await page.evaluate(() => ({
|
|
subtitle: document.querySelector(".ui-page-subtitle")?.textContent?.trim() ?? "",
|
|
projectLinks: document.querySelectorAll('a[href^="/projects/"]').length,
|
|
attentionCards: document.querySelectorAll("article.ui-projects-card").length,
|
|
listRows: document.querySelectorAll(".ui-projects-row").length,
|
|
filters: [...document.querySelectorAll(".ui-projects-filter-chip")].map((el) =>
|
|
(el.textContent || "").trim().replace(/\s+/g, " "),
|
|
),
|
|
drawerCount: document.querySelectorAll('[role="dialog"], [data-drawer]').length,
|
|
}));
|
|
check(
|
|
layout.scrollWidth <= layout.clientWidth + 2,
|
|
`${viewport.tag}: catalog has horizontal overflow`,
|
|
);
|
|
check(content.projectLinks > 0, `${viewport.tag}: catalog has no canonical project links`);
|
|
check(content.drawerCount === 0, `${viewport.tag}: retired project drawer is still mounted`);
|
|
return { ...layout, ...content };
|
|
}
|
|
|
|
async function auditProfile(page, viewport, expectedId) {
|
|
await page.waitForSelector("#project-context-title", { timeout: 30_000 });
|
|
const layout = await auditLayout(page, viewport);
|
|
const content = await page.evaluate(() => ({
|
|
name: document.querySelector(".app-page h1")?.textContent?.trim() ?? "",
|
|
sectionLinks: [
|
|
...document.querySelectorAll('nav[aria-label="Project profile sections"] a'),
|
|
].map((el) => (el.textContent || "").trim()),
|
|
workspaceLinks: [
|
|
...document.querySelectorAll('nav[aria-label="Project workspace views"] a'),
|
|
].map((el) => ({
|
|
label: (el.textContent || "").trim(),
|
|
href: el.getAttribute("href"),
|
|
})),
|
|
sectionIds: ["overview", "context", "plan", "activity"].filter((id) =>
|
|
document.getElementById(id),
|
|
),
|
|
contextSummary:
|
|
document
|
|
.querySelector("#project-context-title")
|
|
?.parentElement?.parentElement?.textContent?.trim()
|
|
.replace(/\s+/g, " ")
|
|
.slice(0, 180) ?? "",
|
|
}));
|
|
check(
|
|
locationPath(page) === `/projects/${expectedId}`,
|
|
`${viewport.tag}: profile is not canonical`,
|
|
);
|
|
check(
|
|
layout.scrollWidth <= layout.clientWidth + 2,
|
|
`${viewport.tag}: profile has horizontal overflow`,
|
|
);
|
|
check(content.sectionIds.length === 4, `${viewport.tag}: profile is missing anchored sections`);
|
|
check(
|
|
content.workspaceLinks.length === 4,
|
|
`${viewport.tag}: workspace switcher does not have four views`,
|
|
);
|
|
check(content.name.length > 0, `${viewport.tag}: project profile has no name`);
|
|
return { ...layout, ...content };
|
|
}
|
|
|
|
function locationPath(page) {
|
|
return new URL(page.url()).pathname;
|
|
}
|
|
|
|
async function verifyWorkspaceLinks(page, projectName, projectId) {
|
|
const nav = page.getByRole("navigation", { name: "Project workspace views" });
|
|
|
|
await nav.getByRole("link", { name: "Chat" }).click();
|
|
await page.waitForURL(
|
|
(url) => url.pathname === "/loki" && url.searchParams.get("project") === projectName,
|
|
{ timeout: 30_000 },
|
|
);
|
|
await page.waitForTimeout(500);
|
|
|
|
await page
|
|
.getByRole("navigation", { name: "Project workspace views" })
|
|
.getByRole("link", { name: "Control" })
|
|
.click();
|
|
await page.waitForURL(
|
|
(url) => url.pathname === "/control" && url.searchParams.get("focus") === projectName,
|
|
{ timeout: 30_000 },
|
|
);
|
|
await page.waitForTimeout(500);
|
|
|
|
await page
|
|
.getByRole("navigation", { name: "Project workspace views" })
|
|
.getByRole("link", { name: "Terminal" })
|
|
.click();
|
|
await page.waitForURL(
|
|
(url) => url.pathname === "/terminal" && url.searchParams.get("tab") === projectName,
|
|
{ timeout: 30_000 },
|
|
);
|
|
await page.waitForTimeout(500);
|
|
|
|
await page
|
|
.getByRole("navigation", { name: "Project workspace views" })
|
|
.getByRole("link", { name: "Profile" })
|
|
.click();
|
|
await page.waitForURL((url) => url.pathname === `/projects/${projectId}`, { timeout: 30_000 });
|
|
}
|
|
|
|
const browser = await chromium.launch({
|
|
headless: process.env.HEADLESS !== "0",
|
|
executablePath: process.env.CHROME_PATH || "/usr/bin/google-chrome",
|
|
});
|
|
|
|
const report = { base, viewports: [], consoleErrors: [] };
|
|
|
|
try {
|
|
for (const viewport of viewports) {
|
|
const context = await browser.newContext({
|
|
viewport: { width: viewport.width, height: viewport.height },
|
|
isMobile: viewport.isMobile,
|
|
deviceScaleFactor: 1,
|
|
});
|
|
const page = await context.newPage();
|
|
page.on("console", (message) => {
|
|
if (message.type() === "error")
|
|
report.consoleErrors.push({ viewport: viewport.tag, text: message.text() });
|
|
});
|
|
page.on("pageerror", (error) =>
|
|
report.consoleErrors.push({ viewport: viewport.tag, text: error.message }),
|
|
);
|
|
|
|
await login(page);
|
|
await page.goto(`${base}/projects`, { waitUntil: "load", timeout: 60_000 });
|
|
await waitForCatalog(page);
|
|
await page.waitForTimeout(500);
|
|
|
|
const catalog = await auditCatalog(page, viewport);
|
|
await page.screenshot({
|
|
path: path.join(outDir, `${viewport.tag}-catalog.png`),
|
|
fullPage: true,
|
|
});
|
|
|
|
const firstProject = page.locator('a[href^="/projects/"]').first();
|
|
const href = await firstProject.getAttribute("href");
|
|
const projectId = href?.split("/").filter(Boolean).at(-1);
|
|
check(Boolean(projectId), `${viewport.tag}: could not resolve first project id`);
|
|
|
|
await firstProject.click();
|
|
await page.waitForURL((url) => url.pathname === `/projects/${projectId}`, { timeout: 30_000 });
|
|
const profile = await auditProfile(page, viewport, projectId);
|
|
const projectName = profile.name;
|
|
await page.screenshot({
|
|
path: path.join(outDir, `${viewport.tag}-profile.png`),
|
|
fullPage: true,
|
|
});
|
|
|
|
await page.goBack();
|
|
await page.waitForURL((url) => url.pathname === "/projects");
|
|
await waitForCatalog(page);
|
|
|
|
await page.goto(`${base}/projects?open=${projectId}`, { waitUntil: "load", timeout: 60_000 });
|
|
await page.waitForURL((url) => url.pathname === `/projects/${projectId}`, { timeout: 30_000 });
|
|
|
|
if (viewport.tag === "mobile-390" || viewport.tag === "desktop") {
|
|
await verifyWorkspaceLinks(page, projectName, projectId);
|
|
}
|
|
|
|
report.viewports.push({
|
|
viewport: viewport.tag,
|
|
projectId,
|
|
projectName,
|
|
catalog,
|
|
profile,
|
|
browserBack: "pass",
|
|
legacyRedirect: "pass",
|
|
connectedWorkspace:
|
|
viewport.tag === "mobile-390" || viewport.tag === "desktop" ? "pass" : "not repeated",
|
|
});
|
|
await context.close();
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
|
|
const ignoredConsoleErrors = report.consoleErrors.filter(
|
|
({ text }) =>
|
|
!/favicon|Failed to load resource.*404|ResizeObserver loop/i.test(text) &&
|
|
// ClientFetchError minifies to a bare class name in production builds, so
|
|
// match the stable authjs error URL rather than the constructor name.
|
|
!(
|
|
isLocal &&
|
|
/bridge\.orangecat\.ch\/sse|Failed to fetch.*authjs\.dev#autherror|net::ERR_FAILED/i.test(
|
|
text,
|
|
)
|
|
),
|
|
);
|
|
|
|
fs.writeFileSync(path.join(outDir, "report.json"), JSON.stringify(report, null, 2));
|
|
check(
|
|
ignoredConsoleErrors.length === 0,
|
|
`Browser console errors: ${JSON.stringify(ignoredConsoleErrors)}`,
|
|
);
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
base,
|
|
viewports: report.viewports.map((item) => ({
|
|
viewport: item.viewport,
|
|
project: item.projectName,
|
|
catalogOverflow: item.catalog.overflow.length,
|
|
profileOverflow: item.profile.overflow.length,
|
|
catalogTinyText: item.catalog.tinyText.length,
|
|
profileTinyText: item.profile.tinyText.length,
|
|
catalogSmallTargets: item.catalog.smallTargets.length,
|
|
profileSmallTargets: item.profile.smallTargets.length,
|
|
browserBack: item.browserBack,
|
|
legacyRedirect: item.legacyRedirect,
|
|
connectedWorkspace: item.connectedWorkspace,
|
|
})),
|
|
consoleErrors: ignoredConsoleErrors,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
console.log(`screenshots and report: ${outDir}`);
|