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

test([med-importer-server-routes-importer-test-js-no]): pin ERR_PARTIAL_COMMIT_ISSUES → 422 in importer route

[._.]/ Adam Eivy9f0a015f88c9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index c516630054..6e5a19fb7f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,8 @@
## Changed
+- **[med-importer-server-routes-importer-test-js-no] Pin `ERR_PARTIAL_COMMIT_ISSUES → 422` status mapping in importer route tests.** `server/routes/importer.test.js` previously covered the `ERR_VALIDATION → 400`, `ERR_LOCKED → 409`, and `universeSvc.ERR_NOT_FOUND → 404` entries in `SERVICE_ERROR_STATUS` but not the partial-commit entry that maps `IMPORTER_PARTIAL_COMMIT_ISSUES → 422`. A refactor that dropped the entry would fall through to `asyncHandler`'s generic 500 path, pager-alert on a user-action-recoverable state (universe + series already persisted, only the issue loop rolled back), and strip the `arcAlreadyPersisted` / `skipArcOnRetry` retry signals the client gates the retry-without-arc-overwrite path on — the exact regression `server/routes/importer.js:28-37`'s long comment warns against. New `commit` suite test mocks `commitImport` to reject with `{ code: ERR_PARTIAL_COMMIT_ISSUES, context: { universeId, seriesId, arcAlreadyPersisted, skipArcOnRetry } }`, asserts status 422, asserts `body.code === ERR_PARTIAL_COMMIT_ISSUES`, and asserts the full context object survives `sanitizeContext` and reaches the client. PLAN cited the historical status (`→ 207`); test pins the current implementation (`→ 422`) per the same in-code rationale (207 trips the client `request()` helper's `response.ok === true` branch and mis-toasts the partial commit as a success). 11/11 route tests pass.
+
- **[med-ai-dispatch-server-lib-tuipromptrunner-js-198] TUI prompt-runner output buffer raised 1MB → 8MB and overflow no longer silent.** `server/lib/tuiHandshake.js` `OUTPUT_BUFFER_CAP` / `OUTPUT_BUFFER_HEADROOM` bumped from 1MB / 1.25MB to 8MB / 10MB so realistic full-context LLM replies (~600KB UTF-8 from a 200K-token window plus screen chrome) no longer head-truncate mid-token when the TUI fails to write its response file and the central handler falls back to the cleaned PTY scrape. `server/lib/tuiPromptRunner.js#executeTuiRun` now tracks an `outputBufferTruncated` flag, logs a one-time warning the first time the new cap is exceeded, and surfaces the flag in the run record's `extras` (`outputTruncated`) so /runs can flag responses where the start may have been lost. The pinned-constants test in `tuiHandshake.test.js` was updated with the new sizes; nothing else moved. 1537/1537 server lib tests pass.
- **[drop-redundant-getissue-precheck-comic-cover-render] Comic-cover render routes drop their redundant `getIssue` precheck.** The two comic-issue cover-render routes in `server/routes/pipeline.js` (`/issues/:id/stages/comicPages/cover/render` and `…/back-cover/render`) carried a `prepare: (req) => issuesSvc.getIssue(req.params.id)` callback that ran an extra `data/issues.json` read on every render request — `enqueueComicCover` / `enqueueComicBackCover` already call `loadBibleContext(issueId)` (`server/services/pipeline/visualStages.js:401`), whose first step at `loadBibleContext`:141 is the same `getIssue(issueId)` raising `PIPELINE_ISSUE_NOT_FOUND` with the same `mapServiceError` → 404 mapping. The precheck was a duplicate read with no behavior difference. Dropped the `prepare` callback at both routes and dropped the `prepare` knob from `makeCoverRenderHandler` entirely — there were no other callers. The route comment block now points at the real upstream source of the 404 instead of the misleading "before we spend the bible-context load" framing. Per-request `data/issues.json` reads on the affected routes drop from 2 to 1. 85/85 pipeline route tests pass (including the unchanged `404s for an unknown issue` case, now serviced from `loadBibleContext`). Captured `[audit-remaining-getissue-prechecks-in-pipeline-routes]` as a follow-up to sweep the same precheck pattern at ~10 other sites in pipeline.js where the called service may already raise the same error.
diff --git a/PLAN.md b/PLAN.md
index 53a4ed6efa..64a1707130 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -20,7 +20,6 @@ _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-tests-no-direct-tests-for-executetuirun-pty] **[MED][TESTS]** No direct tests for `executeTuiRun` PTY mechanics — idle-complete, hard-timeout, missing-binary early-fail, `emitRunStarted` shape, CLAUDECODE env stripping. The new `tuiPromptRunner.test.js` only covers `cleanTuiResponse`.
-- [ ] [med-importer-server-routes-importer-test-js-no] **[MED][IMPORTER]** `server/routes/importer.test.js` — no test pins `ERR_PARTIAL_COMMIT_ISSUES → 207` status mapping. Future refactor that drops the entry from `SERVICE_ERROR_STATUS` would 500 on partial commits and trigger pager alerts (the in-code comment's stated regression).
- [ ] [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`.
diff --git a/server/routes/importer.test.js b/server/routes/importer.test.js
index d1d4f6973f..2bdd8d37ea 100644
--- a/server/routes/importer.test.js
+++ b/server/routes/importer.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import express from 'express';
import { request } from '../lib/testHelper.js';
import importerRoutes from './importer.js';
-import { ERR_VALIDATION, ERR_LOCKED, IMPORTER_SOURCE_CHAR_LIMIT } from '../services/importer.js';
+import { ERR_VALIDATION, ERR_LOCKED, ERR_PARTIAL_COMMIT_ISSUES, IMPORTER_SOURCE_CHAR_LIMIT } from '../services/importer.js';
import * as universeSvc from '../services/universeBuilder.js';
import * as seriesSvc from '../services/pipeline/series.js';
import { ARC_ROLES, ARC_SHAPE_IDS } from '../lib/storyArc.js';
@@ -202,4 +202,42 @@ describe('POST /api/importer/commit', () => {
// alone wouldn't catch the regression.
expect(res.body.code).toBe(universeSvc.ERR_NOT_FOUND);
});
+
+ it('returns 422 with preserved context when the service throws ERR_PARTIAL_COMMIT_ISSUES', async () => {
+ // Pins the SERVICE_ERROR_STATUS entry for ERR_PARTIAL_COMMIT_ISSUES.
+ // Dropping the entry would fall through to the generic 500 handler,
+ // pager-alert on a user-action-recoverable partial commit, and strip
+ // the arcAlreadyPersisted/skipArcOnRetry retry signals the client
+ // gates the retry-without-arc-overwrite path on.
+ const err = Object.assign(
+ new Error('universe and series saved; 2 of 3 issues failed and were rolled back'),
+ {
+ code: ERR_PARTIAL_COMMIT_ISSUES,
+ context: {
+ universeId: 'uni-1',
+ seriesId: 'ser-1',
+ arcAlreadyPersisted: true,
+ skipArcOnRetry: true,
+ },
+ },
+ );
+ importerSvc.commitImport.mockRejectedValue(err);
+ const app = buildApp();
+ const res = await request(app).post('/api/importer/commit').send({
+ universeId: 'uni-1',
+ seriesId: 'ser-1',
+ canonSelections: { characters: [], places: [], objects: [] },
+ arc: null,
+ seasons: [],
+ issues: [{ title: 'I1', arcPosition: 1 }],
+ });
+ expect(res.status).toBe(422);
+ expect(res.body.code).toBe(ERR_PARTIAL_COMMIT_ISSUES);
+ expect(res.body.context).toEqual({
+ universeId: 'uni-1',
+ seriesId: 'ser-1',
+ arcAlreadyPersisted: true,
+ skipArcOnRetry: true,
+ });
+ });
});