mirror of
https://github.com/giancarloerra/socraticode.git
synced 2026-07-03 14:05:21 +02:00
fix: linked projects use base hash without branch suffix
resolveLinkedCollections() was calling projectIdFromPath() for linked projects, which with SOCRATICODE_BRANCH_AWARE=true appended the linked project's git branch to its ID. Linked projects indexed without branch-aware mode don't have __branch collections, so lookups failed. Extract coreProjectId() helper (hash-only, no branch suffix) and use it for linked projects. Also fix dedup to compare collection names instead of raw IDs to handle the branch suffix mismatch. Adds unit test verifying linked collection names are branch-agnostic.
This commit is contained in:
+17
-6
@@ -61,12 +61,11 @@ export function projectIdFromPath(folderPath: string): string {
|
||||
}
|
||||
return explicit;
|
||||
}
|
||||
const normalized = path.resolve(folderPath);
|
||||
let id = createHash("sha256").update(normalized).digest("hex").slice(0, 12);
|
||||
let id = coreProjectId(folderPath);
|
||||
|
||||
// Branch-aware mode: append sanitized branch name to isolate per-branch indexes
|
||||
if (process.env.SOCRATICODE_BRANCH_AWARE === "true") {
|
||||
const branch = detectGitBranch(normalized);
|
||||
const branch = detectGitBranch(path.resolve(folderPath));
|
||||
if (branch) {
|
||||
id = `${id}__${sanitizeBranchName(branch)}`;
|
||||
}
|
||||
@@ -75,6 +74,16 @@ export function projectIdFromPath(folderPath: string): string {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core project ID: SHA-256 hash of the resolved path, without branch suffix.
|
||||
* Used internally by resolveLinkedCollections so linked projects always
|
||||
* resolve to their base collection regardless of SOCRATICODE_BRANCH_AWARE.
|
||||
*/
|
||||
function coreProjectId(folderPath: string): string {
|
||||
const normalized = path.resolve(folderPath);
|
||||
return createHash("sha256").update(normalized).digest("hex").slice(0, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive a Qdrant collection name for a project's code chunks.
|
||||
*/
|
||||
@@ -170,9 +179,11 @@ export function resolveLinkedCollections(
|
||||
|
||||
const linked = loadLinkedProjects(resolvedRoot);
|
||||
for (const linkedPath of linked) {
|
||||
const linkedId = projectIdFromPath(linkedPath);
|
||||
// Skip if same project ID (e.g. worktrees sharing SOCRATICODE_PROJECT_ID)
|
||||
if (linkedId === currentId) continue;
|
||||
// Use base hash (no branch suffix) — linked projects are resolved by their
|
||||
// standard collection name regardless of SOCRATICODE_BRANCH_AWARE.
|
||||
const linkedId = coreProjectId(linkedPath);
|
||||
// Skip if same base project (e.g. worktrees sharing SOCRATICODE_PROJECT_ID)
|
||||
if (collectionName(linkedId) === collections[0].name) continue;
|
||||
collections.push({
|
||||
name: collectionName(linkedId),
|
||||
label: path.basename(linkedPath),
|
||||
|
||||
@@ -282,6 +282,29 @@ describe("config", () => {
|
||||
// Different collection names
|
||||
expect(collections[0].name).not.toBe(collections[1].name);
|
||||
});
|
||||
|
||||
it("linked collections use base hash without branch suffix when SOCRATICODE_BRANCH_AWARE is true", () => {
|
||||
process.env.SOCRATICODE_BRANCH_AWARE = "true";
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, ".socraticode.json"),
|
||||
JSON.stringify({ linkedProjects: ["../linked-lib"] }),
|
||||
);
|
||||
|
||||
// Get linked collection name with branch-aware on
|
||||
const withBranch = resolveLinkedCollections(projectDir);
|
||||
expect(withBranch).toHaveLength(2);
|
||||
const linkedNameWithBranch = withBranch[1].name;
|
||||
|
||||
// Get linked collection name with branch-aware off
|
||||
delete process.env.SOCRATICODE_BRANCH_AWARE;
|
||||
const withoutBranch = resolveLinkedCollections(projectDir);
|
||||
const linkedNameWithoutBranch = withoutBranch[1].name;
|
||||
|
||||
// Linked project collection name must be identical regardless of SOCRATICODE_BRANCH_AWARE
|
||||
expect(linkedNameWithBranch).toBe(linkedNameWithoutBranch);
|
||||
// And must NOT contain a branch suffix (double-underscore)
|
||||
expect(linkedNameWithBranch).not.toContain("__");
|
||||
});
|
||||
});
|
||||
|
||||
// ── Branch awareness ────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user