Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: pregate attestation follow-ups from #12299 review (#12302)

[._.]/ Adam Eivyb71517672a7b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 698bc643b3..67f7035891 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -331,6 +331,12 @@ jobs:
if: steps.server-modules-usable.outcome != 'success'
run: npm ci --prefix server
+ # The server runner also globs ../autofixer/**/*.test.js (ui.js imports
+ # express, resolved from autofixer/node_modules). Shards are separate
+ # checkouts, so the impact job's resolution check does not reach them.
+ - name: Install autofixer dependencies
+ run: npm ci --prefix autofixer
+
# server/.npmrc pins ignore-scripts=true, so the allowlisted packages need
# this explicit rebuild. Same condition as the install: whenever this job
# builds the tree it will cache, it must build a rebuilt one — and the
@@ -1036,6 +1042,12 @@ jobs:
if: steps.server-modules-usable.outcome != 'success'
run: npm ci --prefix server
+ # The server runner also globs ../autofixer/**/*.test.js (ui.js imports
+ # express, resolved from autofixer/node_modules). Shards are separate
+ # checkouts, so the impact job's resolution check does not reach them.
+ - name: Install autofixer dependencies
+ run: npm ci --prefix autofixer
+
# server/.npmrc pins ignore-scripts=true, so the allowlisted packages need
# this explicit rebuild. Same condition as the install: whenever this job
# builds the tree it will cache, it must build a rebuilt one — and the
diff --git a/scripts/check-import-case.js b/scripts/check-import-case.js
index 84cf8a132d..7389ccbf68 100644
--- a/scripts/check-import-case.js
+++ b/scripts/check-import-case.js
@@ -35,14 +35,98 @@ const DYNAMIC_IMPORT_RE = /\bimport\(\s*['"]([^'"]+)['"]\s*\)/g;
const NEW_URL_RE = /new URL\(\s*['"]([^'"]+)['"]\s*,\s*import\.meta\.url\s*\)/g;
const COMPLETIONS = ['', '.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '/index.js', '/index.jsx', '/index.ts', '/index.tsx'];
-/** Every relative specifier in a module's source, in source order. */
+/**
+ * Classify every character of a module so specifier regexes can ignore text
+ * that is not executable: comments and template-literal text are blanked in
+ * `code` (newlines kept, so line anchors still work), and `inString` marks
+ * characters inside a quoted string. Regex literals are skipped by a
+ * previous-token heuristic; `${…}` inside a template is code again.
+ */
+function scanCode(source) {
+ const code = source.split('');
+ const inString = new Uint8Array(source.length);
+ const blank = (from, to) => {
+ for (let i = from; i < to; i += 1) if (code[i] !== '\n') code[i] = ' ';
+ };
+ const templates = []; // brace depth at which each open `${` resumes template text
+ let depth = 0;
+ let prev = ''; // last significant code character
+ let i = 0;
+ const readTemplate = (from) => {
+ let j = from + 1;
+ while (j < source.length) {
+ if (source[j] === '\\') j += 2;
+ else if (source[j] === '`') { blank(from, j + 1); return j + 1; }
+ else if (source[j] === '$' && source[j + 1] === '{') {
+ blank(from, j + 2);
+ templates.push(depth);
+ depth += 1;
+ return j + 2;
+ } else j += 1;
+ }
+ blank(from, source.length);
+ return source.length;
+ };
+ while (i < source.length) {
+ const ch = source[i];
+ const two = source.slice(i, i + 2);
+ if (two === '//') {
+ let j = source.indexOf('\n', i);
+ if (j < 0) j = source.length;
+ blank(i, j);
+ i = j;
+ } else if (two === '/*') {
+ let j = source.indexOf('*/', i + 2);
+ j = j < 0 ? source.length : j + 2;
+ blank(i, j);
+ i = j;
+ } else if (ch === '"' || ch === "'") {
+ let j = i + 1;
+ while (j < source.length && source[j] !== ch && source[j] !== '\n') j += source[j] === '\\' ? 2 : 1;
+ inString.fill(1, i, Math.min(j + 1, source.length));
+ i = j + 1;
+ prev = ch;
+ } else if (ch === '`') {
+ i = readTemplate(i);
+ prev = '`';
+ } else if (ch === '/' && (prev === '' || '(,=:[!&|?{};+-*%<>~^'.includes(prev))) {
+ let j = i + 1;
+ let inClass = false;
+ while (j < source.length && source[j] !== '\n' && (inClass || source[j] !== '/')) {
+ if (source[j] === '\\') j += 1;
+ else if (source[j] === '[') inClass = true;
+ else if (source[j] === ']') inClass = false;
+ j += 1;
+ }
+ inString.fill(1, i, Math.min(j + 1, source.length));
+ i = j + 1;
+ prev = '/';
+ } else {
+ if (ch === '{') depth += 1;
+ else if (ch === '}') {
+ depth -= 1;
+ if (templates.length > 0 && templates[templates.length - 1] === depth) {
+ templates.pop();
+ i = readTemplate(i);
+ prev = '`';
+ continue;
+ }
+ }
+ if (!/\s/.test(ch)) prev = ch;
+ i += 1;
+ }
+ }
+ return { code: code.join(''), inString };
+}
+
+/** Every relative specifier in a module's executable code, in source order. */
export function relativeSpecifiers(source) {
- const code = source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
+ const { code, inString } = scanCode(source);
const found = [...staticImportSpecifiersFromSource(code)];
for (const re of [DYNAMIC_IMPORT_RE, NEW_URL_RE]) {
re.lastIndex = 0;
let match;
- while ((match = re.exec(code)) !== null) found.push(match[1]);
+ while ((match = re.exec(code)) !== null) if (!inString[match.index]) found.push(match[1]);
}
return found.filter((specifier) => specifier.startsWith('./') || specifier.startsWith('../'))
.map((specifier) => specifier.split(/[?#]/)[0]);
diff --git a/scripts/check-import-case.test.js b/scripts/check-import-case.test.js
index 4edf89058b..0358265cc7 100644
--- a/scripts/check-import-case.test.js
+++ b/scripts/check-import-case.test.js
@@ -31,6 +31,21 @@ describe('relativeSpecifiers', () => {
});
});
+describe('relativeSpecifiers ignores non-executable text', () => {
+ it('skips specifier-shaped text inside strings, template literals and regex literals but keeps template expressions', () => {
+ const source = [
+ 'const a = "import(\x27./InString.js\x27)";',
+ "const b = 'new URL(\"./InUrl.js\", import.meta.url)';",
+ "const c = `import('./InTemplate.js')\nimport x from './TemplateStatic.js';`;",
+ "const d = /import\\('.\\/InRegex.js'\\)/;",
+ "const e = `${await import('./InExpression.js')}`;",
+ "const f = 4 / 2; const g = await import('./Real.js');",
+ "const h = '/* not a comment'; const i = await import('./AfterString.js');",
+ ].join('\n');
+ expect(relativeSpecifiers(source)).toEqual(['./InExpression.js', './Real.js', './AfterString.js']);
+ });
+});
+
describe('importCaseMismatches', () => {
it('flags a case-only mismatch in each import shape and resolves extension and index completions', () => {
const source = "import a from './foo.js';\nconst b = import('./util/helpers');\nconst c = new URL('./DATA.json', import.meta.url);\nimport d from './lib';";
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 47b2a8b5f8..d2c72982c3 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -1664,6 +1664,10 @@ const isRunnerConfig = (path) => FULL_TRIGGER_RULES.some((rule) => rule.re.test(
const isSourceUnder = (path, prefixes) => isExecutable(path) && !isTestFile(path) && !isDocumentationOnly(path)
&& prefixes.some((prefix) => path.startsWith(prefix));
+// A full-mode runner selects every test it owns, so `files` is empty there and
+// the membership check alone would let a base-side test change slip through.
+const selectsTest = (selection, runner, path) => selection.files.includes(path) || (selection.mode === 'full' && runnerForTest(path) === runner);
+
/**
* Per stage, whether a base-side path could change that stage's outcome:
* (a) a test file the plan selected for the runner, (b) a non-test source
@@ -1671,8 +1675,8 @@ const isSourceUnder = (path, prefixes) => isExecutable(path) && !isTestFile(path
* is the first offending path, for the refusal reason.
*/
const STAGE_DRIFT_RULES = Object.freeze({
- server: (plan, path) => plan.server.files.includes(path) || isSourceUnder(path, RUNNER_ROOTS.server) || WORKSPACE_CACHE_SERVER_INPUTS.has(path),
- client: (plan, path) => plan.client.files.includes(path) || isSourceUnder(path, RUNNER_ROOTS.client) || WORKSPACE_CACHE_CLIENT_INPUTS.has(path),
+ server: (plan, path) => selectsTest(plan.server, 'server', path) || isSourceUnder(path, RUNNER_ROOTS.server) || WORKSPACE_CACHE_SERVER_INPUTS.has(path),
+ client: (plan, path) => selectsTest(plan.client, 'client', path) || isSourceUnder(path, RUNNER_ROOTS.client) || WORKSPACE_CACHE_CLIENT_INPUTS.has(path),
lint: (plan, path) => isLintSurface(path),
build: (plan, path) => isSourceUnder(path, ['client/']) || WORKSPACE_CACHE_CLIENT_INPUTS.has(path),
smoke: (plan, path) => isSourceUnder(path, ['server/']) || path === 'scripts/smoke-boot.js' || WORKSPACE_CACHE_SERVER_INPUTS.has(path),
diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.js
index 8709bb9f7c..8d5c28d79a 100644
--- a/scripts/ci-test-plan.test.js
+++ b/scripts/ci-test-plan.test.js
@@ -2089,6 +2089,14 @@ describe('pregate attestation', () => {
expect(refusedBy(null)).toHaveLength(8);
});
+ it('treats every runner-owned test as selected when the plan runs a runner in full mode', () => {
+ const plan = fullPlan();
+ expect(plan.server).toMatchObject({ mode: 'full', files: [] });
+ const refusedBy = (drift) => Object.keys(attestationDrift(plan, drift)).sort();
+ expect(refusedBy(['server/lib/anything.test.js'])).toEqual(['lint', 'server']);
+ expect(refusedBy(['client/src/anything.test.jsx'])).toEqual(['client', 'lint']);
+ });
+
it('skips the attested stages, reports full=false, and leaves the CI-only jobs alone', () => {
const plan = fullPlan();
expect(plan).toMatchObject({ full: true, windows: true, linuxContainment: true, promptHistory: true, db: true, build: true, smoke: true });
diff --git a/scripts/pregate-attest.js b/scripts/pregate-attest.js
index a6c9e1cd05..a6427a18f5 100644
--- a/scripts/pregate-attest.js
+++ b/scripts/pregate-attest.js
@@ -105,10 +105,10 @@ const refusal = (message) => Object.assign(new Error(message), { refusal: true }
* so this is testable without a repository.
*
* @param {object} report - the parsed receipt
- * @param {{sha: string, treeOf: (sha: string) => string|null, isPushed: (sha: string) => boolean, remote: string, defaultMergeBase?: string|null, os?: string, node?: number}} commit
+ * @param {{sha: string, treeOf: (sha: string) => string|null, isPushed: (sha: string) => boolean, remote: string, defaultMergeBase?: string|null}} commit
* @returns {{sha: string, tree: string, stages: string[], description: string, notes: string[]}}
*/
-export function planAttestation(report, { sha, treeOf, isPushed, remote, defaultMergeBase = null, os = process.platform, node = nodeMajor(process.version) }) {
+export function planAttestation(report, { sha, treeOf, isPushed, remote, defaultMergeBase = null }) {
if (!report || typeof report !== 'object') throw refusal(`no receipt at ${PREGATE_REPORT_PATH}; ${RERUN}`);
if (typeof report.plan?.downgraded !== 'boolean') {
throw refusal(`receipt at ${PREGATE_REPORT_PATH} predates attestation (no plan.downgraded); ${RERUN}`);
@@ -117,6 +117,12 @@ export function planAttestation(report, { sha, treeOf, isPushed, remote, default
if (report.treeStable !== true) {
throw refusal(`the working tree changed while pregate ran (${String(report.tree).slice(0, 12)} → ${String(report.treeAfterRun).slice(0, 12)}); ${RERUN}`);
}
+ // The runtime the stages ran on is the receipt's, not the attesting process's.
+ const os = report.runtime?.platform;
+ const node = nodeMajor(report.runtime?.node);
+ if (typeof os !== 'string' || !/^[a-z0-9]+$/.test(os) || node === null) {
+ throw refusal(`receipt at ${PREGATE_REPORT_PATH} has no valid runtime (platform/node); ${RERUN}`);
+ }
const tree = treeOf(sha);
if (!tree) throw refusal(`cannot resolve ${sha}^{tree}: is ${sha.slice(0, 9)} a commit in this checkout?`);
if (tree !== report.tree) {
@@ -176,7 +182,7 @@ export function resolveRepository(remoteUrl, { ghRepoView }) {
*
* @returns {number} the process exit code
*/
-export function runAttest({ argv = [], cwd = REPO_ROOT, exec = spawnSync, log = console.log, error = console.error, readReceipt = defaultReadReceipt, platform = process.platform, nodeVersion = process.version } = {}) {
+export function runAttest({ argv = [], cwd = REPO_ROOT, exec = spawnSync, log = console.log, error = console.error, readReceipt = defaultReadReceipt } = {}) {
let options;
try {
options = parseArgs(argv);
@@ -245,7 +251,7 @@ export function runAttest({ argv = [], cwd = REPO_ROOT, exec = spawnSync, log =
// `<remote>/main` when the symbolic ref was never set.
const defaultBranch = git(['symbolic-ref', '--short', '-q', `refs/remotes/${remote}/HEAD`]) || `${remote}/main`;
const defaultMergeBase = git(['merge-base', defaultBranch, sha]);
- const attestation = planAttestation(readReceipt(cwd), { sha, treeOf, isPushed, remote, defaultMergeBase, os: platform, node: nodeMajor(nodeVersion) });
+ const attestation = planAttestation(readReceipt(cwd), { sha, treeOf, isPushed, remote, defaultMergeBase });
attestation.notes.forEach((note) => log(`⚠️ ${note}.`));
const request = statusRequest(repository, { ...attestation, targetUrl: options.targetUrl });
diff --git a/scripts/pregate-attest.test.js b/scripts/pregate-attest.test.js
index 3a78a6e6b8..031aac40bf 100644
--- a/scripts/pregate-attest.test.js
+++ b/scripts/pregate-attest.test.js
@@ -28,7 +28,7 @@ const plan = { full: false, reason: 'scoped', server: { mode: 'files', files: []
/** A receipt as pregate writes it, with the given stage outcomes. */
const receipt = ({ stages, tree = TREE, treeAfterRun = tree, downgraded = false, skipped = [], base = { ref: 'origin/main', sha: BASE } }) => buildPregateReport({
plan, options: { base: base.ref }, base, head: { sha: SHA }, tree, treeAfterRun, stages, skipped,
- runtime: {}, startedAt: 's', finishedAt: 'f', downgraded,
+ runtime: { node: 'v26.10.0', platform: OS }, startedAt: 's', finishedAt: 'f', downgraded,
});
describe('attestation encoding', () => {
@@ -139,7 +139,7 @@ describe('repository resolution', () => {
});
describe('planAttestation', () => {
- const commit = { sha: SHA, treeOf: () => TREE, isPushed: () => true, remote: 'origin', defaultMergeBase: BASE, os: OS, node: NODE };
+ const commit = { sha: SHA, treeOf: () => TREE, isPushed: () => true, remote: 'origin', defaultMergeBase: BASE };
const green = receipt({ stages: [stage('scan'), stage('lint'), stage('server'), stage('smoke')] });
it('attests exactly the passed stages of a green, stable receipt on a pushed commit with that tree', () => {
@@ -170,7 +170,7 @@ describe('planAttestation', () => {
expect(result.stages).toEqual(['scan', 'smoke', 'db']);
expect(result.notes[0]).toMatch(/not attesting lint, server, client: the receipt was planned against base fffffffff \(HEAD~1\), not the default branch's merge base eeeeeeeee/);
// The probe shape: no base sha recorded at all.
- const probe = { passed: true, treeStable: true, tree: TREE, options: { base: 'HEAD~1' }, base: { ref: 'HEAD~1' }, plan: { downgraded: false }, stages: [stage('scan'), stage('server')] };
+ const probe = { runtime: green.runtime, passed: true, treeStable: true, tree: TREE, options: { base: 'HEAD~1' }, base: { ref: 'HEAD~1' }, plan: { downgraded: false }, stages: [stage('scan'), stage('server')] };
expect(planAttestation(probe, commit).stages).toEqual(['scan']);
// An unresolved default merge base fails the same way.
expect(planAttestation(green, { ...commit, defaultMergeBase: null }).stages).toEqual(['scan', 'smoke']);
@@ -178,6 +178,14 @@ describe('planAttestation', () => {
expect(() => planAttestation(receipt({ stages: [stage('server')], base: { ref: 'HEAD~1', sha: 'f'.repeat(40) } }), commit)).toThrow(/attests no stage.*not attesting server/);
});
+ it('describes the receipt\'s runtime, not the attesting process\'s, and refuses a receipt without a valid one', () => {
+ const elsewhere = { ...green, runtime: { node: 'v22.3.0', platform: 'linux' } };
+ expect(planAttestation(elsewhere, commit).description).toBe(`tree=${TREE} os=linux node=22 stages=scan,lint,server,smoke`);
+ for (const runtime of [undefined, {}, { node: 'v26.10.0' }, { platform: OS }, { node: 'garbage', platform: OS }, { node: 'v26.10.0', platform: 'Mac OS' }]) {
+ expect(() => planAttestation({ ...green, runtime }, commit), JSON.stringify(runtime)).toThrow(/no valid runtime/);
+ }
+ });
+
it('refuses when nothing attestable passed', () => {
const guardsOnly = receipt({ stages: [stage('server')], downgraded: true });
expect(() => planAttestation(guardsOnly, commit)).toThrow(/attests no stage/);
@@ -207,7 +215,7 @@ describe('runAttest', () => {
];
const green = receipt({ stages: [stage('scan'), stage('lint'), stage('db', 'passed', 'provision'), stage('db', 'passed', 'suite')] });
const io = () => { const out = []; const err = []; return { out, err, log: (line) => out.push(line), error: (line) => err.push(line) }; };
- const run = (options) => runAttest({ platform: OS, nodeVersion: 'v26.10.0', ...options });
+ const run = (options) => runAttest(options);
it('posts the status through gh on the upstream remote with the receipt-derived description', () => {
const calls = [];