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: stub process.cwd() in dataRoot/installState tests so they pass from a worktree (#3372)

[._.]/ Adam Eivy82f40f332241
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index b4485039e7..ac65b87c1c 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -163,6 +163,7 @@
- **[issue-3358] An unreachable `gh` no longer looks like a quiet repo — and an agent can no longer report success having filed no PR.** Around thirty call sites ran `gh` and turned *any* failure into an empty result, so a firewalled or unauthenticated CLI was indistinguishable from a repo with nothing going on: the PR watcher saw no PRs, the branch reconciler classified every pushed branch as "needs a PR" (and would have had an agent open duplicates on top of the ones already open), the issue reconciler saw nothing to reconcile, and none of it logged a distinguishable error. Those reads now answer with three states instead of two — the forge said nothing, the forge said nothing *exists*, or we could not ask — and every forge-dependent scheduled job (`pr-watcher`, `branch-reconcile`, `issue-reconcile`, layered intelligence, self-diagnostics) probes `gh` first and skips the cycle with one clear line rather than executing against a forge it cannot read. Separately, a run whose task shape promised a pull request is now verified against the forge before it is recorded complete: an agent that commits, pushes over SSH (unaffected by an outbound block) and then fails to create the PR is recorded as needing attention with the branch named, not as "Completed successfully" — and "we could not confirm the PR" is kept distinct from "there is no PR", so a network outage is treated as environmental instead of denting the task type's measured success rate.
- **[issue-3359] The prompt-integrity snapshot now pins prompt bytes instead of the machine that generated it.** `taskPromptDefaults.test.js` hashes every current and preserved-historical prompt body against a checked-in snapshot, because editing a preserved body silently strands every other install on a prompt it can no longer recognize as an upgradable default. Prompt bodies embed this install's API origin, so hashing normalized it away first — but only the *runtime* origin, while the historical bodies written before that interpolation existed hardcode `http://localhost:5555`. The snapshot therefore only reproduced on a machine whose own origin happened to equal that literal: set a custom host, or merely run the suite in a shell with `PORT` set (as every CoS agent does), and five untouched bodies hashed differently and the suite failed reporting drift that had not happened. Regenerating the snapshot there would have been the damaging fix — it blesses whatever edited a preserved body, which is the one thing this test exists to catch. Hashing now collapses the frozen legacy origin too, which reproduces the committed snapshot byte for byte on every install, and the shared hasher is what both the test and a new `scripts/regen-prompt-integrity-snapshot.js` use, so the regeneration path can no longer normalize differently from the assertion. The guard is also in the CI planner's always-run list now: it covers a cross-install contract nothing else covers, so no impact scope may scope it out.
- **[issue-3365] A pinned browser read now closes its own scratch tab, instead of every call site being expected to remember.** `navigateToUrlPinned` opens a fresh Chrome tab per call and tore it down itself on a refusal, but on success handed the caller a tab the caller was supposed to close — a convention that had already been broken twice, once leaving a tab behind for every catalog URL ingested and once for every Stacker News identity check, each fixed by hand-writing another close at the call site. The function already knows which case it is in: a caller that passes `evaluateExpression` did its DOM read on that same session and wants nothing back, while a caller that omits one wants the tab *as* the deliverable. So teardown now defaults to on exactly when an expression was supplied, the three read call sites no longer close anything, and the browser handoff and `POST /api/browser/navigate` still get their tab. `closeAfterRead: false` remains for a future caller that wants to read and keep the tab.
+- **[issue-3372] The server suite no longer fails two tests just because it was run from a CoS agent's worktree.** `resolveInstallRoot()` refuses a pinned data root that resolves into `data/cos/worktrees/…`, so worktree-version code can never be talked into reading or writing the live install's data (#1947) — and two tests were quietly leaning on the ambient working directory in a way that tripped exactly that guard. The relative-pin test expected `join(process.cwd(), 'some/rel')`, which inside a claim worktree resolves to a worktree path the resolver correctly refuses; the install-state test asserted that the migration ledger is read from `PATHS.installRoot`, which inside a worktree is itself a worktree path the reader deliberately short-circuits, so the call it asserted never happened. Both now pin the value they depend on — a stubbed cwd and a fixed non-worktree install root — instead of inheriting it from wherever the suite happens to be checked out. The refusal behavior is unchanged and now has a test for the relative-pin case too, and the install-state test asserts its pinned root differs from the code checkout, so it is a real check rather than a tautology on a normal install.
## Three.js Models
diff --git a/server/lib/dataRoot.test.js b/server/lib/dataRoot.test.js
index 579c5bac01..4f1ec5bbf6 100644
--- a/server/lib/dataRoot.test.js
+++ b/server/lib/dataRoot.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, afterEach } from 'vitest';
+import { describe, it, expect, afterEach, vi } from 'vitest';
import { join, sep } from 'path';
import { DATA_ROOT_ENV, resolveInstallRoot, isWorktreeRoot } from './dataRoot.js';
@@ -6,6 +6,7 @@ const REAL_ROOT = join(sep, 'Users', 'me', 'PortOS');
afterEach(() => {
delete process.env[DATA_ROOT_ENV];
+ vi.restoreAllMocks();
});
describe('resolveInstallRoot', () => {
@@ -26,12 +27,24 @@ describe('resolveInstallRoot', () => {
});
it('resolves a relative PORTOS_DATA_ROOT to an absolute path', () => {
+ // Pin the cwd a relative pin resolves against (#3372): the suite itself runs
+ // from a CoS/claim worktree checkout often enough that the ambient cwd would
+ // resolve to a `data/cos/worktrees/…` path — which the resolver correctly
+ // REFUSES as a leaked pin (#1947), making the assertion checkout-dependent.
+ const cwd = join(REAL_ROOT, 'server');
+ vi.spyOn(process, 'cwd').mockReturnValue(cwd);
process.env[DATA_ROOT_ENV] = 'some/rel';
const out = resolveInstallRoot(REAL_ROOT);
- expect(out).toBe(join(process.cwd(), 'some', 'rel'));
+ expect(out).toBe(join(cwd, 'some', 'rel'));
expect(out).not.toBe(REAL_ROOT);
});
+ it('IGNORES a relative pin that resolves into a worktree checkout (leak safety #1947)', () => {
+ vi.spyOn(process, 'cwd').mockReturnValue(join(REAL_ROOT, 'data', 'cos', 'worktrees', 'agent-xyz', 'server'));
+ process.env[DATA_ROOT_ENV] = 'some/rel';
+ expect(resolveInstallRoot(REAL_ROOT)).toBe(REAL_ROOT);
+ });
+
it('IGNORES an override that itself points at a worktree checkout (symmetric leak safety)', () => {
process.env[DATA_ROOT_ENV] = join(REAL_ROOT, 'data', 'cos', 'worktrees', 'agent-xyz');
expect(resolveInstallRoot(REAL_ROOT)).toBe(REAL_ROOT);
diff --git a/server/services/installState.test.js b/server/services/installState.test.js
index 842f84e393..efc829d8c6 100644
--- a/server/services/installState.test.js
+++ b/server/services/installState.test.js
@@ -10,6 +10,19 @@ vi.mock('../../scripts/run-migrations.js', () => ({
listPendingMigrations: vi.fn(async () => [])
}));
+// Pin the data install root the default wiring reads (#3372). The real
+// PATHS.installRoot follows the executing checkout, so when this suite runs
+// from a CoS/claim worktree it IS a `data/cos/worktrees/…` path — which the
+// default `listPending` correctly short-circuits (#1947), leaving the
+// default-wiring assertion below with nothing to observe. Pinning a fixed
+// non-worktree value also makes it distinct from PATHS.root, so the assertion
+// genuinely proves the ledger is read from the DATA root, not the code checkout.
+const { INSTALL_ROOT } = vi.hoisted(() => ({ INSTALL_ROOT: '/data-install-root' }));
+vi.mock('../lib/fileUtils.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ return { ...actual, PATHS: { ...actual.PATHS, installRoot: INSTALL_ROOT } };
+});
+
import {
getInstallState,
captureBootCommit,
@@ -205,6 +218,7 @@ describe('getInstallState — pending migrations', () => {
listPendingMigrations.mockClear();
const { listPending, ...optsWithoutInjectedPending } = syncedOpts();
await getInstallState(optsWithoutInjectedPending);
+ expect(PATHS.installRoot).not.toBe(PATHS.root); // the two diverge, so this is a real check
expect(listPendingMigrations).toHaveBeenCalledWith({ rootDir: PATHS.installRoot });
});