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: preserve retired prompt hash history across revisions (#11992)

Adam Eivy1b6154c2f394
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 3747f97ee6..a316d1d2fe 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -360,6 +360,9 @@ export const ALWAYS_RUN_TESTS = [
'server/services/orphanedPartialGc.test.js',
'server/services/providers.shape.test.js',
'server/services/taskPromptDefaults.test.js',
+ // Base-relative retired history guard: JSON edits have no import edge here.
+ // Pregate and CI forward the planner's exact CI_BASE_SHA.
+ 'server/services/taskPromptDefaults/integritySnapshot.guard.test.js',
'server/routeValidationConventions.test.js',
'server/timerCallbackConventions.test.js',
];
diff --git a/server/services/taskPromptDefaults/integritySnapshot.guard.test.js b/server/services/taskPromptDefaults/integritySnapshot.guard.test.js
new file mode 100644
index 0000000000..5eb95343f7
--- /dev/null
+++ b/server/services/taskPromptDefaults/integritySnapshot.guard.test.js
@@ -0,0 +1,67 @@
+/** Retired hashes are irreplaceable cross-install upgrade recognition data. */
+import { describe, expect, it } from 'vitest';
+import { execFileSync } from 'node:child_process';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { PROMPT_VERSIONS } from './versions.js';
+
+const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url));
+const SNAPSHOT_PATH = 'server/services/taskPromptDefaults/integrity.snapshot.json';
+const git = (...args) => execFileSync('git', args, {
+ cwd: REPO_ROOT,
+ encoding: 'utf8',
+ stdio: ['ignore', 'pipe', 'pipe'],
+}).trim();
+
+function missingRetiredHashes(base, current, versions) {
+ return Object.entries(base.PREVIOUS_DEFAULT_PROMPTS).flatMap(([key, hashes]) => {
+ // Matches advancePromptIntegritySnapshot's intentional dropped-key handling.
+ if (versions[key] === undefined) return [];
+ const retained = new Set(current.PREVIOUS_DEFAULT_PROMPTS[key] ?? []);
+ return hashes.filter((hash) => !retained.has(hash)).map((hash) => `${key}: ${hash}`);
+ });
+}
+
+describe('retired prompt hash history (#11992)', () => {
+ it('preserves every base hash for prompts that remain versioned', (context) => {
+ const explicitBase = process.env.CI_BASE_SHA?.trim();
+ let base;
+ if (explicitBase) {
+ // The planner already chose this commit. Do not rebase it, fall back, or
+ // skip a bad explicit SHA: that would silently compare different inputs.
+ base = git('rev-parse', '--verify', `${explicitBase}^{commit}`);
+ } else {
+ try {
+ base = git('merge-base', 'origin/main', 'HEAD');
+ } catch {
+ context.skip('No merge base available; fetch origin/main to check retired prompt history.');
+ return;
+ }
+ }
+ // A resolvable base with a missing/malformed snapshot is an error, not an
+ // empty history. Only an unavailable local base permits skipping.
+ const previous = JSON.parse(git('show', `${base}:${SNAPSHOT_PATH}`));
+ const current = JSON.parse(readFileSync(new URL('./integrity.snapshot.json', import.meta.url), 'utf8'));
+ expect(missingRetiredHashes(previous, current, PROMPT_VERSIONS),
+ `Retired prompt hashes removed since ${base}; restore this upgrade recognition history`,
+ ).toEqual([]);
+ });
+
+ const snapshot = (history) => ({ PREVIOUS_DEFAULT_PROMPTS: history });
+ const base = snapshot({ prompt: ['first', 'second'] });
+
+ it.each([
+ ['one hash', { prompt: ['second'] }, ['prompt: first']],
+ ['the entire key', {}, ['prompt: first', 'prompt: second']],
+ ])('detects deletion of %s', (_name, history, missing) => {
+ expect(missingRetiredHashes(base, snapshot(history), { prompt: 2 })).toEqual(missing);
+ });
+
+ it('allows new hashes without depending on order', () => {
+ expect(missingRetiredHashes(base, snapshot({ prompt: ['third', 'second', 'first'] }), { prompt: 3 })).toEqual([]);
+ });
+
+ it('allows history removal only after the prompt version key is removed', () => {
+ expect(missingRetiredHashes(base, snapshot({}), {})).toEqual([]);
+ });
+});