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: enumerate every fixture issue page before cleanup (#11041)

Adam Eivy391844457fc7
diff --git a/scripts/cleanup-test-data.js b/scripts/cleanup-test-data.js
index d5424b8123..8349c4cd8c 100644
--- a/scripts/cleanup-test-data.js
+++ b/scripts/cleanup-test-data.js
@@ -102,6 +102,24 @@ function parseArgs(argv) {
return out;
}
+// listIssues caps even its unpaginated result. Plan from every page before
+// writing so a parent with more than one page of children remains recoverable.
+async function listAllIssues(listIssues, options = {}) {
+ const issues = [];
+ while (true) {
+ const page = await listIssues({
+ ...options, includeDeleted: false, withHistory: false,
+ paginated: true, offset: issues.length,
+ });
+ if (!Array.isArray(page.items) || !Number.isInteger(page.total) || page.total < 0) {
+ throw new Error('Invalid issue enumeration page');
+ }
+ issues.push(...page.items);
+ if (issues.length >= page.total) return issues;
+ if (page.items.length === 0) throw new Error('Incomplete issue enumeration');
+ }
+}
+
async function cleanup({ apply, services, output }) {
const { listUniverses, deleteUniverse, listSeries, deleteSeries, listIssues, deleteIssue } = services;
if (!apply) {
@@ -143,7 +161,7 @@ async function cleanup({ apply, services, output }) {
// Map series.id → array of live child issues for that series.
const childIssuesBySeries = new Map();
for (const { rec: s } of seriesTargets) {
- const children = await listIssues({ seriesId: s.id, includeDeleted: false });
+ const children = await listAllIssues(listIssues, { seriesId: s.id });
childIssuesBySeries.set(s.id, children);
}
const totalChildIssues = [...childIssuesBySeries.values()].reduce((n, arr) => n + arr.length, 0);
@@ -156,7 +174,7 @@ async function cleanup({ apply, services, output }) {
// Orphan fixture issues: a non-uuid-id issue whose parent series is NOT itself
// a target (so it won't be reached by the cascade above). These are direct
// test-fixture inserts (`iss-live`, `iss-dup`, …) that would otherwise survive.
- const allIssues = await listIssues({ includeDeleted: false });
+ const allIssues = await listAllIssues(listIssues);
const orphanIssueTargets = allIssues.filter(
i => isIssueFixtureId(i.id) && !seriesTargetIds.has(i.seriesId),
);
diff --git a/scripts/cleanup-test-data.test.js b/scripts/cleanup-test-data.test.js
index 0b7b83ad52..424daf4e0e 100644
--- a/scripts/cleanup-test-data.test.js
+++ b/scripts/cleanup-test-data.test.js
@@ -15,7 +15,7 @@ const CHILD_A = `iss-${uuid(4)}`;
const CHILD_B = `iss-${uuid(5)}`;
const REAL_I = `iss-${uuid(6)}`;
-function fixtureStore() {
+function fixtureStore(pageSize = 1000) {
const universes = [
{ id: U, name: ' Test Work ' },
{ id: 'fixture-universe', name: 'Example Universe' },
@@ -56,8 +56,13 @@ function fixtureStore() {
const services = {
listUniverses: async options => list(universes, 'universes', options),
listSeries: async options => list(series, 'series', options),
- listIssues: async options => list(issues, options.seriesId ? 'children' : 'all-issues', options)
- .filter(i => !options.seriesId || i.seriesId === options.seriesId),
+ listIssues: async options => {
+ expect(options.paginated).toBe(true);
+ const key = options.seriesId ? 'children' : 'all-issues';
+ if (failures.has(`${key}:${options.offset}`)) throw new Error('Later issue page unavailable');
+ const rows = list(issues, key, options).filter(i => !options.seriesId || i.seriesId === options.seriesId);
+ return { items: rows.slice(options.offset, options.offset + pageSize), total: rows.length };
+ },
deleteUniverse: remove(universes, 'universe'),
deleteSeries: remove(series, 'series'),
deleteIssue: remove(issues, 'issue'),
@@ -128,6 +133,30 @@ describe('fixture cleanup CLI workflow', () => {
expect(store.attempts).toEqual([]);
});
+ it('plans every page before deleting a parent with over 1000 children or a late orphan', async () => {
+ const store = fixtureStore();
+ const extraChildren = Array.from({ length: 1001 }, (_, index) => ({
+ id: `iss-${uuid(index + 100)}`, seriesId: S, number: index + 3,
+ }));
+ store.issues.push(...extraChildren, { id: 'iss-late-orphan', seriesId: REAL_S, number: 3 });
+ const result = await store.run();
+ expect(result.code).toBe(0);
+ const parentPosition = store.completed.indexOf(`series:${S}`);
+ expect(store.completed.slice(2, parentPosition)).toEqual(
+ [CHILD_A, CHILD_B, ...extraChildren.map(child => child.id)].map(id => `issue:${id}`),
+ );
+ expect(store.completed).toContain('issue:iss-late-orphan');
+ expect(result.logs).toContain('✅ Tombstoned 2 universe(s) + 2 series + 1006 issue(s).');
+ });
+
+ it.each(['children:2', 'all-issues:2'])('refuses all writes if a later %s page is unavailable', async key => {
+ const store = fixtureStore(2);
+ store.issues.push({ id: `iss-${uuid(20)}`, seriesId: S, number: 3 });
+ store.failures.add(key);
+ expectFailure(await store.run());
+ expect(store.attempts).toEqual([]);
+ });
+
it('keeps the parent and remaining UUID child live after a child failure, then retries only remaining work', async () => {
const store = fixtureStore();
store.failures.add(`issue:${CHILD_B}`);