Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor(doctor): our own implementation of the #6060 fix (#6060)

time-attack62108807eda7
diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.md
index 63e36a0356..751100ccfd 100644
--- a/docs/guides/troubleshooting.md
+++ b/docs/guides/troubleshooting.md
@@ -62,7 +62,7 @@
| Check | What it could not read | Fix |
| --- | --- | --- |
-| `multi_source_drift` | a source's `local_path` root or a directory below it (`details.unreadable_sources`), the walk hit its bound (`details.limit` files / `details.timeout_ms`), or the git toplevel of a source pinned to git-root slugs could not be resolved (`details.git_root_skipped`) | fix the path or permissions (`gbrain sources status`); for a large source re-run with `GBRAIN_DRIFT_LIMIT=<files> GBRAIN_DRIFT_TIMEOUT_MS=<ms> gbrain doctor`; for a git-root source, make its `local_path` a git checkout that `git` can read |
+| `multi_source_drift` | a source's `local_path` root or a directory below it (`details.unreadable_sources`), the walk hit its bound (`details.limit` files / `details.timeout_ms`), or, for a source whose slugs are pinned to its git root, where `local_path` sits in its git work tree (`details.git_root_skipped`) | fix the path or permissions (`gbrain sources status`); for a large source re-run with `GBRAIN_DRIFT_LIMIT=<files> GBRAIN_DRIFT_TIMEOUT_MS=<ms> gbrain doctor`; for a git-root source, check that `git -C <local_path> rev-parse --show-prefix` succeeds (a checkout git can read and that it trusts) |
| `embed_staleness` | the stale-chunk count (the embed worker's own predicate) | the reason names the database error; re-run `gbrain doctor` once it is fixed |
| `schema_pack_consistency`, `schema_pack_source_drift` | the pages or config query, or a source's active schema pack | `gbrain schema lint --with-db` runs the same classification locally; `gbrain schema active` debugs pack resolution |
diff --git a/llms-full.txt b/llms-full.txt
index 225a9b2b71..ba24414494 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -10103,7 +10103,7 @@ Source: https://raw.githubusercontent.com/garrytan/gbrain/master/docs/guides/tro
| Check | What it could not read | Fix |
| --- | --- | --- |
-| `multi_source_drift` | a source's `local_path` root or a directory below it (`details.unreadable_sources`), the walk hit its bound (`details.limit` files / `details.timeout_ms`), or the git toplevel of a source pinned to git-root slugs could not be resolved (`details.git_root_skipped`) | fix the path or permissions (`gbrain sources status`); for a large source re-run with `GBRAIN_DRIFT_LIMIT=<files> GBRAIN_DRIFT_TIMEOUT_MS=<ms> gbrain doctor`; for a git-root source, make its `local_path` a git checkout that `git` can read |
+| `multi_source_drift` | a source's `local_path` root or a directory below it (`details.unreadable_sources`), the walk hit its bound (`details.limit` files / `details.timeout_ms`), or, for a source whose slugs are pinned to its git root, where `local_path` sits in its git work tree (`details.git_root_skipped`) | fix the path or permissions (`gbrain sources status`); for a large source re-run with `GBRAIN_DRIFT_LIMIT=<files> GBRAIN_DRIFT_TIMEOUT_MS=<ms> gbrain doctor`; for a git-root source, check that `git -C <local_path> rev-parse --show-prefix` succeeds (a checkout git can read and that it trusts) |
| `embed_staleness` | the stale-chunk count (the embed worker's own predicate) | the reason names the database error; re-run `gbrain doctor` once it is fixed |
| `schema_pack_consistency`, `schema_pack_source_drift` | the pages or config query, or a source's active schema pack | `gbrain schema lint --with-db` runs the same classification locally; `gbrain schema active` debugs pack resolution |
diff --git a/src/commands/doctor/schema-pack-checks.ts b/src/commands/doctor/schema-pack-checks.ts
index 0c21e3b80c..68f812132f 100644
--- a/src/commands/doctor/schema-pack-checks.ts
+++ b/src/commands/doctor/schema-pack-checks.ts
@@ -213,27 +213,27 @@ export function multiSourceDriftAdvice(count: number, sampleStr: string, managed
}
/**
- * Note appended when one or more sources were excluded from the
- * multi_source_drift walk: pinned to slug_root_mode='git-root' (#4342) with a
- * local_path whose git toplevel could not be resolved, so the git-root prefix
- * their slugs carry cannot be derived. Comparing them against
- * local_path-relative slugs would produce false-positive drift (and delete
- * advice naming an unrelated default page). Skipped, not mismatched.
+ * Disclosure appended to multi_source_drift when sources pinned to
+ * slug_root_mode='git-root' (#4342) were left out because git could not
+ * place their local_path in a work tree, so the prefix their slugs carry is
+ * unknown. They are unverified, not drifted: checking them against
+ * local_path-relative slugs would invent drift and delete advice.
*/
export function multiSourceDriftGitRootSkipNote(skippedIds: string[]): string {
return (
- ` ${skippedIds.length} source(s) not checked (pinned to git-root slugs, but the git toplevel ` +
- `of local_path could not be resolved, so their slug prefix cannot be derived): ${skippedIds.join(', ')}.`
+ ` ${skippedIds.length} source(s) not checked (pinned to git-root slugs, but git could not locate ` +
+ `local_path inside a work tree, so the slug prefix sync used is unknown): ${skippedIds.join(', ')}.`
);
}
const DRIFT_DOCS = 'docs/guides/troubleshooting.md#not-verified-doctor-checks';
/**
- * #5432: one multi_source_drift verdict for the local and remote doctor. A
- * truncated walk, an unreadable source root/subdirectory or a skipped
- * git-root source is "not verified" (warn), never "no drift"; the walk
- * bounds, unreadable and skipped sources ride in details.
+ * #5432: one multi_source_drift verdict for the local and remote doctor.
+ * Anything that leaves a source uncompared (a truncated walk, an unreadable
+ * root or subdirectory, a git-root source git cannot place) is "not
+ * verified" (warn), never "no drift"; details carry the walk bounds and the
+ * unreadable and skipped sources.
*/
export function multiSourceDriftCheck(
result: MisroutedResult,
@@ -285,21 +285,15 @@ export function multiSourceDriftCheck(
details: { ...details, code: 'not_verified', verified: false },
};
}
- // A skipped source (git-root-pinned, git toplevel unresolvable) was not
- // verified, so 'ok' would misreport "verified clean"; when EVERY candidate
- // was skipped, no source was checked at all.
- if (result.git_root_skipped.length > 0) {
- const allSkipped = result.git_root_skipped.length >= candidateSources;
- return {
- name: 'multi_source_drift',
- status: 'warn',
- message: allSkipped
- ? `Multi-source drift check performed no verification${skipNote}`
- : `No cross-source slug drift among checked sources.${skipNote}`,
- details: { ...details, code: 'not_verified', verified: false },
- };
+ if (result.git_root_skipped.length === 0) {
+ return { name: 'multi_source_drift', status: 'ok', message: 'No cross-source slug drift detected.', details };
}
- return { name: 'multi_source_drift', status: 'ok', message: 'No cross-source slug drift detected.', details };
+ // Skipped sources were never compared, so this cannot be "no drift" even
+ // when every checked sibling was clean.
+ const lead = result.git_root_skipped.length >= candidateSources
+ ? 'Multi-source drift check performed no verification'
+ : 'No cross-source slug drift among checked sources.';
+ return { name: 'multi_source_drift', status: 'warn', message: lead + skipNote, details: { ...details, code: 'not_verified', verified: false } };
}
/** #5432: the drift check itself failed (e.g. the sources query); report it instead of dropping the check. */
diff --git a/src/core/multi-source-drift.ts b/src/core/multi-source-drift.ts
index 28969a3e34..8c76e5516e 100644
--- a/src/core/multi-source-drift.ts
+++ b/src/core/multi-source-drift.ts
@@ -30,24 +30,24 @@
* yields zero files, NOT a thrown crash that takes down the whole doctor
* run; the source is reported in `unreadable_sources` (#5432) so doctor
* says "not verified" instead of "no drift".
- * - Slug shape follows the source's slug-root pin (#4342, src/core/sync-anchor.ts).
- * Unpinned and `'source-root'` sources get `local_path`-relative slugs.
- * A `'git-root'` pin means sync minted slugs from the git-root-relative
- * path, so the walk's paths are prefixed with `local_path`'s subdir under
- * the git toplevel. That prefix is empty when `local_path` IS the
- * toplevel, which is what managed sync pins for a source at its repo root.
- * Comparing against the wrong shape would false-positive (with delete
- * advice naming an unrelated page), so a git-root-pinned source whose git
- * toplevel cannot be resolved is skipped and reported via
- * `git_root_skipped` instead.
+ * - Slugs are rebuilt the way sync minted them, which depends on the
+ * source's slug-root pin (#4342, src/core/sync-anchor.ts). Unpinned and
+ * `'source-root'` sources slug the `local_path`-relative path. A
+ * `'git-root'` source slugs the path relative to its git work tree, so
+ * every walked path gets `local_path`'s own location in the work tree in
+ * front of it; that location is empty when `local_path` is the toplevel,
+ * which is what managed sync pins for a source at its repo root (#5862).
+ * When git cannot place `local_path` in a work tree the source is not
+ * compared at all (a wrong slug shape false-positives, with delete advice
+ * naming an unrelated page) and is reported in `git_root_skipped`.
*/
-import { readdirSync, lstatSync, statSync, realpathSync } from 'fs';
+import { readdirSync, lstatSync, statSync } from 'fs';
import { join, relative } from 'path';
import type { BrainEngine } from './engine.ts';
import { pathToSlug } from './sync.ts';
import { readSlugRootMode } from './sync-anchor.ts';
-import { discoverGitRoot, gitRelativePath, isWithinRoot } from './sync-git.ts';
+import { git } from './sync-git.ts';
export interface SourceWithPath {
id: string;
@@ -67,10 +67,10 @@ export interface MisroutedResult {
count: number;
sample: MisroutedSample[];
/**
- * Source IDs pinned to slug_root_mode 'git-root' whose local_path is readable
- * but whose git toplevel cannot be resolved: the git-root prefix sync used
- * cannot be derived, so the source is excluded rather than checked against
- * the wrong slug shape.
+ * Readable sources pinned to slug_root_mode 'git-root' that git cannot
+ * place inside a work tree (not a checkout, git missing or refusing the
+ * directory). The prefix their slugs carry is unknown, so they were not
+ * compared rather than compared against the wrong slug shape.
*/
git_root_skipped: string[];
/**
@@ -210,25 +210,20 @@ async function batchProbeExistence(
}
/**
- * The git-root-relative scope of `localPath`, '/'-separated and '' when it IS
- * the toplevel, from the realpaths of both ends as managed sync computes it
- * (src/core/persistence/sync-discovery.ts). null when the git toplevel of
- * `localPath` cannot be resolved (not a repository, git missing or refusing
- * the directory), so the caller reports the source instead of guessing a
- * slug shape.
+ * The path prefix sync put in front of a walked file's `local_path`-relative
+ * path before slugging it: '' unless the source is pinned to 'git-root', and
+ * then `local_path`'s location in its git work tree as git reports it
+ * (`rev-parse --show-prefix`: '' at the toplevel, 'sub/dir/' below it, with
+ * symlinks resolved, the scope managed sync derives). null when git cannot
+ * place `local_path` in a work tree.
*/
-function gitRootScope(localPath: string): string | null {
- let gitRoot: string;
- let root: string;
+async function syncedPathPrefix(engine: BrainEngine, src: SourceWithPath): Promise<string | null> {
+ if (await readSlugRootMode(engine, src.id) !== 'git-root') return '';
try {
- gitRoot = realpathSync.native(discoverGitRoot(localPath));
- root = realpathSync.native(localPath);
+ return git(src.local_path, ['rev-parse', '--show-prefix'], [], 30_000, { silenceStderr: true });
} catch {
- // discoverGitRoot rethrows every git failure as one error: the caller
- // reports the source in git_root_skipped, so doctor says it was not checked.
return null;
}
- return isWithinRoot(root, gitRoot) ? gitRelativePath(gitRoot, root) : null;
}
/**
@@ -267,21 +262,16 @@ export async function findMisroutedPages(
else if (unreadableDirs > 0) unreadable.push({ source_id: src.id, reason: 'subdirs_unreadable', dirs: unreadableDirs });
if (files.length === 0) continue;
- // A 'git-root' pin prefixes the walk's paths with local_path's subdir
- // under the git toplevel ('' at the toplevel); see the header. Resolved
- // after the walk, so an unreadable local_path reports as root_unreadable.
- let gitScope = '';
- if (await readSlugRootMode(engine, src.id) === 'git-root') {
- const scope = gitRootScope(src.local_path);
- if (scope === null) {
- gitRootSkipped.push(src.id);
- continue;
- }
- gitScope = scope;
+ // Asked only once the walk found files, so a missing local_path stays
+ // root_unreadable instead of reading as a git-root skip.
+ const prefix = await syncedPathPrefix(engine, src);
+ if (prefix === null) {
+ gitRootSkipped.push(src.id);
+ continue;
}
// Convert FS paths to canonical slugs (lowercased, extension stripped).
- const slugs = Array.from(new Set(files.map(f => pathToSlug(gitScope ? `${gitScope}/${f.relPath}` : f.relPath))));
+ const slugs = Array.from(new Set(files.map(f => pathToSlug(prefix + f.relPath))));
const existenceMap = await batchProbeExistence(engine, slugs, src.id);
for (const slug of slugs) {
diff --git a/test/multi-source-drift.test.ts b/test/multi-source-drift.test.ts
index 4935087822..4bce236c94 100644
--- a/test/multi-source-drift.test.ts
+++ b/test/multi-source-drift.test.ts
@@ -14,6 +14,10 @@
* DB row at X AND default has its own legitimate slug) → ok (NOT a
* false positive).
* 5. FS walk hits limit → status `warn 'check skipped, walk too large'`.
+ *
+ * #5862: sources pinned to git-root slugs are compared using the prefix git
+ * reports for local_path inside its work tree (empty at the toplevel), and a
+ * source git cannot place keeps the doctor verdict at "not verified".
*/
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
@@ -175,8 +179,7 @@ describe('findMisroutedPages — heuristic correctness', () => {
expect(result.sample[0].slug).toBe('topics/mdx-page');
});
- test('case 8 (#4712, #5862): a git-root-pinned source outside any git repository is skipped, and doctor says why', async () => {
- // Not a git repository: the git-root prefix sync used cannot be derived.
+ test('case 8 (#4712): a git-root-pinned source is skipped, not false-positived', async () => {
const root = makeTmpRoot('case8');
seedFile(root, 'page.md');
@@ -197,43 +200,6 @@ describe('findMisroutedPages — heuristic correctness', () => {
expect(result.count).toBe(0);
expect(result.sample).toEqual([]);
expect(result.git_root_skipped).toEqual(['src-case8']);
- const check = multiSourceDriftCheck(result, 1, 'local');
- expect(check).toMatchObject({ status: 'warn', details: { code: 'not_verified', verified: false } });
- expect(check.message).toContain('git toplevel of local_path could not be resolved');
- expect(check.message).not.toContain('#4712');
- });
-
- test('case 8b (#5862): a skipped git-root source keeps doctor at not verified when a sibling is checked clean', async () => {
- const skippedRoot = makeTmpRoot('case8b-skipped');
- seedFile(skippedRoot, 'page.md');
- await runSources(engine, ['add', 'src-case8b-gr', '--no-federated']);
- await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = $2`, [skippedRoot, 'src-case8b-gr']);
- await writeSlugRootMode(engine, 'src-case8b-gr', 'git-root');
- const cleanRoot = makeTmpRoot('case8b-clean');
- seedFile(cleanRoot, 'topics/clean.md');
- await runSources(engine, ['add', 'src-case8b-sr', '--no-federated']);
- await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = $2`, [cleanRoot, 'src-case8b-sr']);
-
- const result = await findMisroutedPages(engine, [
- { id: 'src-case8b-gr', local_path: skippedRoot },
- { id: 'src-case8b-sr', local_path: cleanRoot },
- ]);
- expect(result).toMatchObject({ count: 0, git_root_skipped: ['src-case8b-gr'], unreadable_sources: [] });
- const check = multiSourceDriftCheck(result, 2, 'local');
- expect(check).toMatchObject({ status: 'warn', details: { code: 'not_verified', verified: false } });
- expect(check.message).toStartWith('No cross-source slug drift among checked sources.');
- expect(check.message).toContain('src-case8b-gr');
- });
-
- test('case 8c (#5862): a git-root source whose local_path is missing reports root_unreadable, not a git-root skip', async () => {
- await runSources(engine, ['add', 'src-case8c', '--no-federated']);
- const missing = join(makeTmpRoot('case8c'), 'gone');
- await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = $2`, [missing, 'src-case8c']);
- await writeSlugRootMode(engine, 'src-case8c', 'git-root');
-
- const result = await findMisroutedPages(engine, [{ id: 'src-case8c', local_path: missing }]);
- expect(result.git_root_skipped).toEqual([]);
- expect(result.unreadable_sources).toEqual([{ source_id: 'src-case8c', reason: 'root_unreadable', dirs: 1 }]);
});
test('case 9 (#4712): git-root skip does not mask real drift on a sibling source-root source', async () => {
@@ -260,42 +226,111 @@ describe('findMisroutedPages — heuristic correctness', () => {
expect(result.sample[0]).toMatchObject({ slug: 'people/eve', intended_source: 'src-case9-sr' });
expect(result.git_root_skipped).toEqual(['src-case9-gr']);
});
+});
- // #5862: inside a git repository every pin is checkable. A 'git-root' pin
- // means sync minted slugs from the git-root-relative path: no prefix when
- // local_path is the repo root (what managed sync pins there), the subdir
- // in slug spelling otherwise. Each row seeds a healthy page at the source,
- // a misrouted one at default, and an unrelated default page at the
- // local_path-relative slug that only the wrong slug shape would flag.
- const GIT_REPO_CASES: Array<{ label: string; scope: string; pin: 'git-root' | 'source-root' | null; slugPrefix: string; viaSymlink?: boolean }> = [
- { label: 'unpinned source at the repo root', scope: '', pin: null, slugPrefix: '' },
- { label: 'git-root source at the repo root (empty prefix)', scope: '', pin: 'git-root', slugPrefix: '' },
- { label: 'git-root source in a subdir (prefixed slugs)', scope: 'Team Notes', pin: 'git-root', slugPrefix: 'team-notes/' },
- { label: 'git-root source whose local_path is a symlink into a subdir', scope: 'Team Notes', pin: 'git-root', slugPrefix: 'team-notes/', viaSymlink: true },
- { label: 'source-root source in a subdir', scope: 'Team Notes', pin: 'source-root', slugPrefix: '' },
- ];
- for (const [i, c] of GIT_REPO_CASES.entries()) {
- test(`case 10.${i} (#5862): ${c.label}: misroute detected, no false positive`, async () => {
- const repo = makeTmpRoot(`case10-${i}`);
- execFileSync('git', ['-C', repo, 'init', '-q'], { stdio: 'pipe' });
- const root = c.scope ? join(repo, c.scope) : repo;
- seedFile(root, 'people/alice.md');
- seedFile(root, 'people/bob.md');
- // Sync derives the prefix from the realpath, so a symlinked local_path must too.
- const localPath = c.viaSymlink ? join(makeTmpRoot(`case10-${i}-link`), 'link') : root;
- if (c.viaSymlink) symlinkSync(root, localPath);
- const id = `src-case10-${i}`;
- await runSources(engine, ['add', id, '--no-federated']);
- await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = $2`, [localPath, id]);
- if (c.pin) await writeSlugRootMode(engine, id, c.pin);
- await engine.putPage(`${c.slugPrefix}people/alice`, { type: 'person', title: 'Alice', compiled_truth: '.' }, { sourceId: id });
- await engine.putPage('people/alice', { type: 'person', title: 'Unrelated', compiled_truth: '.' });
- await engine.putPage(`${c.slugPrefix}people/bob`, { type: 'person', title: 'Bob', compiled_truth: '.' });
-
- const result = await findMisroutedPages(engine, [{ id, local_path: localPath }]);
- expect(result.git_root_skipped).toEqual([]);
- expect(result.count).toBe(1);
- expect(result.sample).toEqual([{ slug: `${c.slugPrefix}people/bob`, intended_source: id, local_path: localPath }]);
- });
+describe('findMisroutedPages — git-root pins inside a work tree (#5862)', () => {
+ /** A fresh repository; returns `<repo>/<subdir>` (the repo itself for ''). */
+ function gitWorkTree(label: string, subdir: string): string {
+ const repo = makeTmpRoot(label);
+ execFileSync('git', ['init', '-q', repo], { stdio: 'pipe' });
+ const dir = subdir ? join(repo, subdir) : repo;
+ mkdirSync(dir, { recursive: true });
+ return dir;
+ }
+
+ async function registerSource(id: string, localPath: string, pin: 'git-root' | 'source-root' | null): Promise<void> {
+ await runSources(engine, ['add', id, '--no-federated']);
+ await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = $2`, [localPath, id]);
+ if (pin) await writeSlugRootMode(engine, id, pin);
+ }
+
+ /**
+ * Two files under local_path. Sync stored `kept` under the source; `lost`
+ * exists only at default (a misroute). `<plain>/lost` is an unrelated
+ * default page that a wrong (unprefixed) slug shape would also flag.
+ */
+ async function seedPair(id: string, localPath: string, slugPrefix: string, tag: string): Promise<void> {
+ seedFile(localPath, `${tag}/kept.md`);
+ seedFile(localPath, `${tag}/lost.md`);
+ await engine.putPage(`${slugPrefix}${tag}/kept`, { type: 'note', title: 'Kept', compiled_truth: '.' }, { sourceId: id });
+ await engine.putPage(`${slugPrefix}${tag}/lost`, { type: 'note', title: 'Lost', compiled_truth: '.' });
+ if (slugPrefix) await engine.putPage(`${tag}/kept`, { type: 'note', title: 'Unrelated', compiled_truth: '.' });
}
+
+ test('git-root source at its repo toplevel is checked with no prefix', async () => {
+ const root = gitWorkTree('gr-top', '');
+ await registerSource('src-gr-top', root, 'git-root');
+ await seedPair('src-gr-top', root, '', 'grtop');
+
+ const result = await findMisroutedPages(engine, [{ id: 'src-gr-top', local_path: root }]);
+ expect(result.git_root_skipped).toEqual([]);
+ expect(result.sample).toEqual([{ slug: 'grtop/lost', intended_source: 'src-gr-top', local_path: root }]);
+ expect(multiSourceDriftCheck(result, 1, 'local').details).toMatchObject({ code: 'drift_detected' });
+ });
+
+ test('git-root source two levels down gets its work-tree location as the slug prefix', async () => {
+ const root = gitWorkTree('gr-nested', join('Field Notes', '2026'));
+ await registerSource('src-gr-nested', root, 'git-root');
+ await seedPair('src-gr-nested', root, 'field-notes/2026/', 'grnested');
+
+ const result = await findMisroutedPages(engine, [{ id: 'src-gr-nested', local_path: root }]);
+ expect(result.git_root_skipped).toEqual([]);
+ expect(result.count).toBe(1);
+ expect(result.sample.map((s) => s.slug)).toEqual(['field-notes/2026/grnested/lost']);
+ });
+
+ test('a symlinked local_path takes the prefix of the directory it points to', async () => {
+ const real = gitWorkTree('gr-link', 'shared');
+ const link = join(makeTmpRoot('gr-link-alias'), 'alias');
+ symlinkSync(real, link);
+ await registerSource('src-gr-link', link, 'git-root');
+ await seedPair('src-gr-link', link, 'shared/', 'grlink');
+
+ const result = await findMisroutedPages(engine, [{ id: 'src-gr-link', local_path: link }]);
+ expect(result.git_root_skipped).toEqual([]);
+ expect(result.sample).toEqual([{ slug: 'shared/grlink/lost', intended_source: 'src-gr-link', local_path: link }]);
+ });
+
+ test('control: a source-root source in a subdirectory keeps local_path-relative slugs', async () => {
+ const root = gitWorkTree('sr-sub', 'docs');
+ await registerSource('src-sr-sub', root, 'source-root');
+ await seedPair('src-sr-sub', root, '', 'srsub');
+
+ const result = await findMisroutedPages(engine, [{ id: 'src-sr-sub', local_path: root }]);
+ expect(result.sample.map((s) => s.slug)).toEqual(['srsub/lost']);
+ });
+
+ test('a git-root source whose local_path is gone is unreadable, not a git-root skip', async () => {
+ const gone = join(makeTmpRoot('gr-gone'), 'missing');
+ await registerSource('src-gr-gone', gone, 'git-root');
+
+ const result = await findMisroutedPages(engine, [{ id: 'src-gr-gone', local_path: gone }]);
+ expect(result.git_root_skipped).toEqual([]);
+ expect(result.unreadable_sources).toEqual([{ source_id: 'src-gr-gone', reason: 'root_unreadable', dirs: 1 }]);
+ });
+});
+
+describe('multiSourceDriftCheck — skipped git-root sources (#5862)', () => {
+ const clean = { walk_truncated: false, count: 0, sample: [], unreadable_sources: [], limit: 10_000, timeout_ms: 5_000 };
+
+ test('one skipped source beside a clean one is not verified, and says why', () => {
+ const check = multiSourceDriftCheck({ ...clean, git_root_skipped: ['src-outside-git'] }, 2, 'local');
+ expect(check.status).toBe('warn');
+ expect(check.details).toMatchObject({ code: 'not_verified', verified: false, git_root_skipped: ['src-outside-git'] });
+ expect(check.message).toStartWith('No cross-source slug drift among checked sources.');
+ expect(check.message).toContain('src-outside-git');
+ expect(check.message).toContain('work tree');
+ expect(check.message).not.toContain('#4712');
+ });
+
+ test('every candidate skipped means no verification at all', () => {
+ const check = multiSourceDriftCheck({ ...clean, git_root_skipped: ['a', 'b'] }, 2, 'remote');
+ expect(check.status).toBe('warn');
+ expect(check.message).toStartWith('Multi-source drift check performed no verification');
+ });
+
+ test('control: nothing skipped and nothing found is ok', () => {
+ const check = multiSourceDriftCheck({ ...clean, git_root_skipped: [] }, 2, 'local');
+ expect(check).toMatchObject({ status: 'ok', message: 'No cross-source slug drift detected.' });
+ });
});