Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: cover the per-member restore receipt, unmerged targets, included ignore config and split indexes

garrytanac3c2af65960
diff --git a/test/git-door-planned-state.test.ts b/test/git-door-planned-state.test.ts
index fcf54d1337..f2a0b3d93c 100644
--- a/test/git-door-planned-state.test.ts
+++ b/test/git-door-planned-state.test.ts
@@ -41,6 +41,7 @@ import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { readHeadBlockers } from '../src/core/persistence/head-blocker.ts';
import { performManagedSync } from '../src/core/persistence/sync-run.ts';
import { runRepairCommand } from '../src/commands/repair.ts';
+import { maintenancePreflight, publishMaintenancePages } from '../src/core/persistence/prepared-maintenance.ts';
import { durableGitRepo } from './helpers/git-publication.ts';
import { managedBrain, settleManagedGitEffects } from './helpers/managed-brain.ts';
import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
@@ -202,6 +203,28 @@ for (const backend of testBackends()) describe(`[${backend}] the door commits on
expect(git(root, 'rev-parse', `HEAD:${FILE}`)).toBe(git(root, 'hash-object', '--', FILE));
expect(git(root, 'status', '--porcelain')).toBe('');
}, { databaseUrl, setup }), 120_000);
+ // Generated by /ship Step 7 coverage audit (gstack), test-only.
+ // Value: protects=a group publication puts git_index_restored on the receipt of the member whose stale entry it restored, and on no other;
+ // fails_when=group-publish.ts drops onIndexRestored or maps the restored path to the wrong member; why_new=the stale-entry test above runs the
+ // single-write path (coordinator.ts) only; seam=none; no_claim=PGLite never forms publication groups, so this runs on the Postgres arm only
+ if (backend === 'postgres') test('a group publication names the restored path on that member\'s receipt only', () => managedBrain(async ({ engine, ctx, root }) => {
+ await committedPage(engine, ctx);
+ expect(await putPage.handler(ctx, { slug: 'notes/other', content: page('Other'), request_id: randomUUID(), wait_ms: 30_000 })).toMatchObject({ state: 'committed' });
+ expect(await publish(engine, ctx, page('Second'))).toMatchObject({ state: 'committed' });
+ git(root, 'update-index', '--cacheinfo', `100644,${git(root, 'rev-parse', `HEAD^:${FILE}`)},${FILE}`);
+ const maintenance = (await maintenancePreflight(engine, 'default', root))!;
+ const revision = async (slug: string) => (await engine.readPageSnapshot(slug, { sourceId: 'default' }))!.revision;
+ const outcomes = await publishMaintenancePages(engine, maintenance, [
+ { slug: SLUG, content: page('Third'), expectedRevision: await revision(SLUG) },
+ { slug: 'notes/other', content: page('Other two'), expectedRevision: await revision('notes/other') }]);
+ const [mine, other] = outcomes.map(outcome => ('receipt' in outcome ? outcome.receipt : { error: outcome.error }) as Record<string, any>);
+ const head = git(root, 'rev-parse', 'HEAD');
+ expect(mine).toMatchObject({ state: 'committed', persistence: { git_state: 'committed', git_commit: head, git_index_restored: [FILE] } });
+ expect(other).toMatchObject({ state: 'committed', persistence: { git_state: 'committed', git_commit: head } });
+ expect(other!.persistence.git_index_restored).toBeUndefined();
+ expect(await standing(engine, root)).toEqual({ row: 'Third', head: 'Third', disk: 'Third', index: git(root, 'rev-parse', `HEAD:${FILE}`) });
+ expect(git(root, 'status', '--porcelain')).toBe('');
+ }, { databaseUrl, setup }), 120_000);
});
const OLD = new Date('2001-01-01T00:00:00Z');
@@ -312,4 +335,28 @@ describe('door plumbing: the planned state', () => {
expect(git(root, 'rev-parse', ':notes/a.md')).toBe(novel);
expect(git(root, 'rev-parse', 'HEAD')).toBe(commit!);
});
+
+ // Generated by /ship Step 7 coverage audit (gstack), test-only.
+ // Value: protects=a conflicted (unmerged) target is never committed over or resolved by the door, even when its base stage is HEAD^'s version;
+ // fails_when=readIndex keeps a stage 1-3 entry as a plain entry, so the base stage reads as the door's stale refresh and update-index resolves
+ // the conflict; why_new=only stage-0 staged changes are tested; seam=none; no_claim=the unmerged entry is built with update-index --index-info, not a real merge
+ test('an unmerged target refuses git_index_conflict and keeps its stages, also when its base stage is the parent\'s version', async () => {
+ const root = repo({ 'notes/a.md': 'a\n' });
+ const commit = await publishAt(root, 'notes/a.md', 'door\n');
+ const theirs = execFileSync('git', ['-C', root, 'hash-object', '-w', '--stdin'], { input: 'theirs\n', encoding: 'utf8', env }).trim();
+ const stages = [['100644', git(root, 'rev-parse', `${commit}^:notes/a.md`), '1'], ['100644', git(root, 'rev-parse', `${commit}:notes/a.md`), '2'], ['100644', theirs, '3']];
+ execFileSync('git', ['-C', root, 'update-index', '--index-info'], { env,
+ input: [`0 ${'0'.repeat(40)}\tnotes/a.md`, ...stages.map(([mode, oid, stage]) => `${mode} ${oid} ${stage}\tnotes/a.md`)].join('\n') + '\n' });
+ const listed = git(root, 'ls-files', '-s', '--', 'notes/a.md');
+ expect(listed.split('\n')).toHaveLength(3);
+ for (const body of ['door\n', 'novel\n']) {
+ put(root, 'notes/a.md', body);
+ const restored: string[][] = [];
+ expect(await refusal(commitThroughDoor(root, [{ path: join(root, 'notes/a.md'), planned: sha256(body) }], undefined, paths => restored.push(paths))))
+ .toMatchObject({ code: 'git_index_conflict' });
+ expect(restored).toEqual([]);
+ expect(git(root, 'ls-files', '-s', '--', 'notes/a.md')).toBe(listed);
+ expect(git(root, 'rev-parse', 'HEAD')).toBe(commit!);
+ }
+ });
});
diff --git a/test/ignore-rules.test.ts b/test/ignore-rules.test.ts
index c4de0a404e..f6eb384d72 100644
--- a/test/ignore-rules.test.ts
+++ b/test/ignore-rules.test.ts
@@ -146,4 +146,42 @@ describe('ignore filter', () => {
expect(scanIndex(readFileSync(index), 20)).toEqual({ decidable: true, gitlinks: new Set() });
expect(scanIndex(Buffer.from('not an index'), 20).decidable).toBe(false);
});
+
+ // Generated by /ship Step 7 coverage audit (gstack), test-only.
+ // Value: protects=a core.excludesFile set in an included config file (a relative include.path) is read, and an edit of that file is seen;
+ // fails_when=the probe stops resolving include paths or watching included files, so a stale probe clears a path Git now ignores;
+ // why_new=excludes edits are tested only through .git/config; seam=none; no_claim=includeIf conditions (onbranch, gitdir) are not exercised
+ test('a core.excludesFile set through an included config file, and an edit of that file, is seen on the next call', async () => {
+ const root = repo();
+ put(root, 'notes/a.md');
+ git(root, 'add', '-A'); git(root, 'commit', '-qm', 'seed');
+ const markdown = join(root, '.git', 'markdown-excludes'), text = join(root, '.git', 'text-excludes');
+ writeFileSync(markdown, '*.md\n'); writeFileSync(text, '*.txt\n');
+ const included = join(root, '.git', 'included.gitconfig');
+ writeFileSync(included, `[core]\n\texcludesFile = ${text}\n`);
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual([]);
+ git(root, 'config', 'include.path', 'included.gitconfig');
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual([]);
+ writeFileSync(included, `[core]\n\texcludesFile = ${markdown}\n`);
+ expect(gitIgnored(root, ['notes/new.md'])).toEqual(new Set(['notes/new.md']));
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual(['notes/new.md']);
+ writeFileSync(included, `[core]\n\texcludesFile = ${text}\n`);
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual([]);
+ });
+
+ // Generated by /ship Step 7 coverage audit (gstack), test-only.
+ // Value: protects=a split index (entries and skip-worktree bits in the shared index file) is left to Git; fails_when=scanIndex accepts the
+ // required 'link' extension, so the filter decides without seeing the shared entries; why_new=sparse, skip-worktree and v4 are tested, a split
+ // index is not; seam=none; no_claim=a sparse index (sdir extension) is not exercised
+ test('a split index is left to Git', async () => {
+ const root = repo();
+ put(root, 'notes/a.md');
+ git(root, 'add', '-A'); git(root, 'commit', '-qm', 'seed');
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual([]);
+ git(root, 'update-index', '--split-index');
+ expect(scanIndex(readFileSync(join(root, '.git', 'index')), 20).decidable).toBe(false);
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual(['notes/new.md']);
+ git(root, 'update-index', '--no-split-index');
+ expect(await ignoreCandidates(root, ['notes/new.md'])).toEqual([]);
+ });
});