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([med-tests-no-direct-tests-for-executetuirun-pty]): restore original CLAUDECODE env after test, defer emitRunStarted hook-shape test

[._.]/ Adam Eivy4ad10f773d89
diff --git a/PLAN.md b/PLAN.md
index a247f30ef2..4d6dd66ede 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -19,6 +19,7 @@ _Nothing currently parked — pick the next item from the Backlog._
- [ ] [agent-tui-spawn-truncation-warn-parity] **[LOW][AI-DISPATCH]** `server/services/agentTuiSpawning.js:177-179` (and the `rawBuffer` slice at line ~273-274) silently slice the head of the same buffers when they cross `OUTPUT_BUFFER_HEADROOM` / `RAW_BUFFER_HEADROOM`, with no warning and no agent-metadata flag. The companion one-shot runner now sets `outputBufferTruncated` and surfaces it through the run record (see `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]`). Long-running CoS agents using `agentTuiSpawning.js` mostly stream to `output.txt` via `appendAgentOutputLines`, so the buffer overflow here is less load-bearing — but the same warn-once + agent-metadata flag would close the visibility gap. Deferred from `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]` to keep that PR scoped.
- [ ] [med-importer-server-services-importer-test-js-no] **[MED][IMPORTER]** `server/services/importer.test.js` — no test exercises `existingCanonBlock` dedupe wiring. A regression that wires `null` would silently degrade second-pass imports. Assert `mockRunStagedLLM.mock.calls[0][1].existingCanonBlock` contains a seeded character name.
- [ ] [med-canon-server-services-canonusage-js-zero-test] **[MED][CANON]** `server/services/canonUsage.js` — zero test coverage for `getUniverseCanonUsage`. The "Appears-in sort: issueCount desc + alpha tiebreaker" invariant lives at line ~101 with no test. Add a `canonUsage.test.js`.
+- [ ] [add-emitrunstarted-hook-shape-test-to-runner] **[LOW][TESTS]** `server/services/runner.test.js` has no coverage for `emitRunStarted`'s payload shape — `runner.js:198-204` flattens `provider` to `provider?.name || provider?.id` and falls back `model ?? provider?.defaultModel`, but no test pins that contract. The `executeTuiRun` PTY tests intentionally mock `emitRunStarted`, so a regression in the flattening logic (e.g. dropping the `name` preference or breaking the model fallback) would slip past `tuiPromptRunner.test.js`. Add a focused test that registers a `runnerConfig.hooks.onRunStarted` mock, calls `emitRunStarted({ runId, provider, model })` with `{ name, id, defaultModel }` variants, and asserts the hook payload shape. Surfaced by codex review iter 1 during `[med-tests-no-direct-tests-for-executetuirun-pty]`; deferred because the scope of that PR was `executeTuiRun` (not `runner.js`), and the fix touches a different test file.
### Better-audit residue
diff --git a/server/lib/tuiPromptRunner.test.js b/server/lib/tuiPromptRunner.test.js
index 2d7a9e8d90..f75a2da736 100644
--- a/server/lib/tuiPromptRunner.test.js
+++ b/server/lib/tuiPromptRunner.test.js
@@ -315,6 +315,12 @@ describe('executeTuiRun', () => {
});
it('merges provider.envVars and strips CLAUDECODE from the child env so a nested Claude Code TUI is not detected as nested', async () => {
+ // Save + restore the original value: a PortOS-inside-Claude-Code dev
+ // run starts the worker with CLAUDECODE already set, and an
+ // unconditional `delete` would clobber the test of a sibling test.
+ const originalClaudecode = Object.prototype.hasOwnProperty.call(process.env, 'CLAUDECODE')
+ ? process.env.CLAUDECODE
+ : undefined;
process.env.CLAUDECODE = '1';
try {
const provider = {
@@ -333,7 +339,8 @@ describe('executeTuiRun', () => {
ptyInstances[0].emitExit({ exitCode: 0 });
await promise;
} finally {
- delete process.env.CLAUDECODE;
+ if (originalClaudecode === undefined) delete process.env.CLAUDECODE;
+ else process.env.CLAUDECODE = originalClaudecode;
}
});
});