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(issue-7782): include uncommitted work in pregate plans (#7782)

[._.]/ Adam Eivy421721940f77
diff --git a/AGENTS.md b/AGENTS.md
index cec78d99fe..9873cddbcd 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -32,7 +32,7 @@ npm run test:db # DB-backed suites → portos_test ONLY (see Se
npm run pregate # BEFORE EVERY PUSH — local CI-plan checks; limits below
```
-**Run `npm run pregate` on committed work before every push and again after rebasing onto a moved base.** It uses CI's planner and runners, including tree-wide guards for import boundaries, catalog merges, and generated manifests. It does not validate uncommitted changes.
+**Run `npm run pregate` before every push and again after rebasing onto a moved base.** It uses CI's planner and runners, including tree-wide guards for import boundaries, catalog merges, and generated manifests. The local plan includes both committed and uncommitted changes, including untracked files.
A full-suite plan runs only the always-run guards unless `--full` is supplied. DB suites, Windows, client build, and boot smoke are reported but not run by pregate. A green pregate proves only the stages it ran; required CI checks still apply.
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 93d998cac3..4d0b168317 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { execFileSync } from 'child_process';
+import { existsSync } from 'fs';
+import { join } from 'path';
import { isDirectlyInvoked } from './lib/directInvocation.js';
import { writeStepOutput } from './lib/githubOutput.js';
@@ -809,14 +811,14 @@ function fullPlan(changedFiles, reason, options = {}) {
// Git's display output quotes non-ASCII/control characters; trimming also
// changes valid paths. Read raw NUL-delimited paths so selectors stay exact.
-const gitPaths = (args) => execFileSync('git', args, { encoding: 'utf8' })
+const gitPaths = (args, cwd) => execFileSync('git', args, { cwd, encoding: 'utf8' })
.split('\0')
.filter(Boolean);
/** Tracked test files whose text matches `pattern`; `git grep` exit 1 is "none". */
-const gitGrepFiles = (pattern, pathspecs) => {
+const gitGrepFiles = (pattern, pathspecs, cwd) => {
try {
- return gitPaths(['grep', '-z', '-l', '-E', pattern, '--', ...pathspecs]);
+ return gitPaths(['grep', '-z', '-l', '-E', pattern, '--', ...pathspecs], cwd);
} catch (err) {
if (err.status === 1) return [];
throw err;
@@ -866,6 +868,55 @@ export function forceFullReasonFor({ forceFull, baseRef }) {
return null;
}
+/**
+ * Collect the repository-derived inputs that surround the pure plan builder.
+ *
+ * CI leaves `changedFiles` unset and keeps deriving its diff from baseSha. A
+ * local caller may supply the complete committed + working-tree path list; in
+ * that mode files present but not yet tracked are plan inputs too, while paths
+ * deleted from the working tree are deliberately absent from trackedFiles.
+ */
+export function collectPlanInputs({ baseSha, forceFull = false, changedFiles, cwd = process.cwd() }) {
+ const hasChangedFilesOverride = changedFiles !== undefined;
+ const collectedChangedFiles = forceFull
+ ? []
+ : hasChangedFilesOverride
+ ? changedFiles
+ : gitPaths(['diff', '-z', '--name-only', '--diff-filter=ACMRD', `${baseSha}...HEAD`], cwd);
+ const trackedFiles = gitPaths(['ls-files', '-z'], cwd);
+ const presentFiles = hasChangedFilesOverride
+ ? uniqueSorted([
+ ...trackedFiles,
+ ...collectedChangedFiles.filter((path) => existsSync(join(cwd, path))),
+ ]).filter((path) => existsSync(join(cwd, path)))
+ : trackedFiles;
+
+ let appDiff = null;
+ if (!forceFull && collectedChangedFiles.includes('client/src/App.jsx')) {
+ const committedDiff = execFileSync(
+ 'git', ['diff', '--unified=0', `${baseSha}...HEAD`, '--', 'client/src/App.jsx'],
+ { cwd, encoding: 'utf8' },
+ );
+ const workingTreeDiff = hasChangedFilesOverride
+ ? execFileSync('git', ['diff', '--unified=0', 'HEAD', '--', 'client/src/App.jsx'], { cwd, encoding: 'utf8' })
+ : '';
+ appDiff = `${committedDiff}${workingTreeDiff}`;
+ }
+
+ // Every changed executable, non-test source — not only python scripts — gets
+ // a basename lookup: `git grep`-ing tracked test files for its filename finds
+ // the text-reading contract tests (mirror parity, navManifest.js's 20+ client
+ // reads) that no import edge or feature-directory match can reach. Basename
+ // matching is deliberate: a mirror test names the client copy only as e.g.
+ // 'canonPrompt.js', never by its full path. Over-selection here costs
+ // seconds; under-selection is the bug this closes (issue #6363).
+ const pathContractTests = Object.fromEntries(collectedChangedFiles
+ .filter((path) => isExecutable(path) && !isTestFile(path))
+ .map((path) => [path, gitGrepFiles(sourceReferencePattern(path), TEST_FILE_GLOBS, cwd)]));
+
+ return { changedFiles: collectedChangedFiles, trackedFiles: presentFiles, appDiff, pathContractTests };
+}
+
function main() {
const forceFullReason = forceFullReasonFor({
forceFull: process.env.CI_FORCE_FULL === 'true',
@@ -880,23 +931,18 @@ function main() {
if (!forceFull && !base) {
throw new Error('CI_BASE_SHA is required unless the run is forced full (CI_FORCE_FULL=true or CI_BASE_REF=release).');
}
- const changedFiles = forceFull
- ? []
- : gitPaths(['diff', '-z', '--name-only', '--diff-filter=ACMRD', `${base}...HEAD`]);
- const trackedFiles = gitPaths(['ls-files', '-z']);
- const appDiff = forceFull || !changedFiles.includes('client/src/App.jsx')
- ? null
- : execFileSync('git', ['diff', '--unified=0', `${base}...HEAD`, '--', 'client/src/App.jsx'], { encoding: 'utf8' });
- // Every changed executable, non-test source — not only python scripts — gets
- // a basename lookup: `git grep`-ing tracked test files for its filename finds
- // the text-reading contract tests (mirror parity, navManifest.js's 20+ client
- // reads) that no import edge or feature-directory match can reach. Basename
- // matching is deliberate: a mirror test names the client copy only as e.g.
- // 'canonPrompt.js', never by its full path. Over-selection here costs
- // seconds; under-selection is the bug this closes (issue #6363).
- const pathContractTests = Object.fromEntries(changedFiles
- .filter((path) => isExecutable(path) && !isTestFile(path))
- .map((path) => [path, gitGrepFiles(sourceReferencePattern(path), TEST_FILE_GLOBS)]));
+ const changedFilesOverride = process.env.CI_CHANGED_FILES === undefined
+ ? undefined
+ : JSON.parse(process.env.CI_CHANGED_FILES);
+ if (changedFilesOverride !== undefined
+ && (!Array.isArray(changedFilesOverride) || changedFilesOverride.some((path) => typeof path !== 'string'))) {
+ throw new Error('CI_CHANGED_FILES must be a JSON array of repository-relative path strings.');
+ }
+ const { changedFiles, trackedFiles, appDiff, pathContractTests } = collectPlanInputs({
+ baseSha: base,
+ forceFull,
+ changedFiles: changedFilesOverride,
+ });
emitGitHubPlan(buildCiTestPlan(changedFiles, {
trackedFiles,
forceFull,
diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.js
index 0cea8baf6f..0b5114e63e 100644
--- a/scripts/ci-test-plan.test.js
+++ b/scripts/ci-test-plan.test.js
@@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url';
import {
ALWAYS_RUN_TESTS,
buildCiTestPlan,
+ collectPlanInputs,
forceFullReasonFor,
FULL_SUITE_SHARDS,
isRouteOnlyAppDiff,
@@ -112,6 +113,50 @@ it('preserves Git-quoted source and contract paths through the planner CLI', ()
}
});
+it('builds the same plan from an explicit working-tree override as from the equivalent commit', () => {
+ const root = mkdtempSync(join(tmpdir(), 'portos-ci-override-'));
+ const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();
+ const source = 'client/src/App.jsx';
+ const test = 'client/src/App.test.jsx';
+ const write = (path, body) => {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), body);
+ };
+ const commit = () => {
+ git('add', '--all');
+ git('-c', 'user.name=Example Contributor', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', 'commit', '-qm', 'fixture');
+ };
+ const build = (inputs) => buildCiTestPlan(inputs.changedFiles, {
+ trackedFiles: inputs.trackedFiles,
+ appRouteOnly: isRouteOnlyAppDiff(inputs.appDiff),
+ pathContractTests: inputs.pathContractTests,
+ });
+
+ try {
+ git('init', '-q');
+ git('config', 'core.hooksPath', join(root, 'empty-hooks'));
+ write(source, 'export const app = (\n <Routes>\n <Route path="old" />\n </Routes>\n);\n');
+ write(test, "import './App.jsx';\n");
+ commit();
+ const base = git('rev-parse', 'HEAD');
+
+ write(source, 'export const app = (\n <Routes>\n <Route path="new" />\n </Routes>\n);\n');
+ const overridden = build(collectPlanInputs({
+ baseSha: base,
+ changedFiles: [source],
+ cwd: root,
+ }));
+
+ commit();
+ const committed = build(collectPlanInputs({ baseSha: base, cwd: root }));
+ expect(overridden.full).toBe(false);
+ expect(overridden).toEqual(committed);
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});
+
describe('CI test impact planner', () => {
it('skips all expensive jobs for documentation-only changes, keeping the always-run guards', () => {
const plan = buildCiTestPlan([
diff --git a/scripts/pregate.js b/scripts/pregate.js
index 9bd0659d22..0d36d99cd2 100644
--- a/scripts/pregate.js
+++ b/scripts/pregate.js
@@ -114,6 +114,37 @@ export function downgradeFullPlan(plan, trackedFiles) {
const git = (args) => execFileSync('git', args, { cwd: REPO_ROOT, encoding: 'utf8' }).trim();
+const gitPaths = (args, cwd = REPO_ROOT) => execFileSync('git', args, { cwd, encoding: 'utf8' })
+ .split('\0')
+ .filter(Boolean);
+
+/** Paths represented by NUL-delimited `git status --porcelain=v1` output. */
+export function statusPaths(output) {
+ const entries = output.split('\0').filter(Boolean);
+ const paths = [];
+ for (let index = 0; index < entries.length; index += 1) {
+ const entry = entries[index];
+ const status = entry.slice(0, 2);
+ paths.push(entry.slice(3));
+ if (/[RC]/.test(status)) index += 1;
+ }
+ return paths;
+}
+
+/** The committed diff plus every staged, unstaged, deleted, or untracked path. */
+export function collectPregateChangedFiles(baseSha, { cwd = REPO_ROOT } = {}) {
+ const committed = gitPaths(['diff', '-z', '--name-only', '--diff-filter=ACMRD', `${baseSha}...HEAD`], cwd);
+ const status = execFileSync(
+ 'git', ['status', '--porcelain=v1', '-z', '--untracked-files=all'],
+ { cwd, encoding: 'utf8' },
+ );
+ const workingTree = statusPaths(status);
+ return {
+ changedFiles: [...new Set([...committed, ...workingTree])].sort(),
+ workingTreeFiles: [...new Set(workingTree)].sort(),
+ };
+}
+
/** The remote default branch (`origin/main` unless this fork says otherwise). */
function defaultBaseRef() {
const head = spawnSync('git', ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD'], {
@@ -146,13 +177,9 @@ function main() {
const baseSha = mergeBase.stdout.trim();
console.log(`🔎 Planning against ${baseRef} (${baseSha.slice(0, 9)}).`);
- // Uncommitted work is invisible to a `<base>...HEAD` diff, so it is invisible
- // to the plan. Saying so is the difference between "pregate passed" and
- // "pregate passed on what you have committed".
- const dirty = git(['status', '--porcelain']).split('\n').filter(Boolean);
- if (dirty.length > 0) {
- console.log(`⚠️ ${dirty.length} uncommitted change(s) are NOT in this plan — the plan only sees committed work.`);
- console.log('⚠️ Commit first and re-run, or a green pregate says nothing about the edits still in your tree.');
+ const { changedFiles, workingTreeFiles } = collectPregateChangedFiles(baseSha);
+ if (workingTreeFiles.length > 0) {
+ console.log(`📝 Included ${workingTreeFiles.length} uncommitted changed file(s) in this plan.`);
}
const planned = spawnSync(process.execPath, [join(REPO_ROOT, 'scripts', 'ci-test-plan.js')], {
@@ -160,7 +187,15 @@ function main() {
encoding: 'utf8',
// The planner writes step outputs when Actions' env is present; stripping
// it keeps a local run from appending to a stale $GITHUB_OUTPUT file.
- env: { ...process.env, CI_BASE_SHA: baseSha, CI_FORCE_FULL: 'false', CI_BASE_REF: '', GITHUB_OUTPUT: '', GITHUB_STEP_SUMMARY: '' },
+ env: {
+ ...process.env,
+ CI_BASE_SHA: baseSha,
+ CI_CHANGED_FILES: JSON.stringify(changedFiles),
+ CI_FORCE_FULL: 'false',
+ CI_BASE_REF: '',
+ GITHUB_OUTPUT: '',
+ GITHUB_STEP_SUMMARY: '',
+ },
});
if (planned.status !== 0) {
console.error(`❌ ci-test-plan.js failed: ${planned.stderr || planned.error?.message || 'unknown error'}`);
diff --git a/scripts/pregate.test.js b/scripts/pregate.test.js
index e4f69fa6e1..6499179dff 100644
--- a/scripts/pregate.test.js
+++ b/scripts/pregate.test.js
@@ -9,10 +9,22 @@
*/
import { describe, it, expect } from 'vitest';
import { execFileSync } from 'child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs';
+import { tmpdir } from 'os';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
-import { buildCiTestPlan, ALWAYS_RUN_TESTS } from './ci-test-plan.js';
-import { resolvePlanStages, downgradeFullPlan, parseArgs, UNCOVERED_SUITES } from './pregate.js';
+import {
+ buildCiTestPlan,
+ collectPlanInputs,
+ ALWAYS_RUN_TESTS,
+} from './ci-test-plan.js';
+import {
+ collectPregateChangedFiles,
+ resolvePlanStages,
+ downgradeFullPlan,
+ parseArgs,
+ UNCOVERED_SUITES,
+} from './pregate.js';
const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
@@ -111,6 +123,36 @@ describe('UNCOVERED_SUITES', () => {
});
describe('the gate end to end', () => {
+ it('passes an uncommitted new test through the planner override', () => {
+ const root = mkdtempSync(join(tmpdir(), 'portos-pregate-'));
+ const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();
+ const test = 'server/services/example/newBehavior.test.js';
+ try {
+ git('init', '-q');
+ git('config', 'core.hooksPath', join(root, 'empty-hooks'));
+ writeFileSync(join(root, 'README.md'), 'fixture\n');
+ git('add', '--all');
+ git('-c', 'user.name=Example Contributor', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', 'commit', '-qm', 'fixture');
+ const base = git('rev-parse', 'HEAD');
+ mkdirSync(dirname(join(root, test)), { recursive: true });
+ writeFileSync(join(root, test), "import { it } from 'vitest';\nit('works', () => {});\n");
+
+ const { changedFiles, workingTreeFiles } = collectPregateChangedFiles(base, { cwd: root });
+ const inputs = collectPlanInputs({ baseSha: base, changedFiles, cwd: root });
+ const plan = buildCiTestPlan(inputs.changedFiles, {
+ trackedFiles: inputs.trackedFiles,
+ appRouteOnly: false,
+ pathContractTests: inputs.pathContractTests,
+ });
+
+ expect(workingTreeFiles).toContain(test);
+ expect(plan.server.files).toContain(test);
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
// `--base HEAD` rather than the default remote branch: CI clones at depth 2
// with no `origin/main` ref, so the default would abort here on a fetch the
// gate is right to demand of a human and wrong to demand of this test. HEAD