fix(secrets): collapse legacy scope duplicates on rollback and verify repo worktrees

Rolling back the scope-index migration now keeps the newest of a colliding global and Assistant-repo secret, matching the legacy last-write-wins upsert, so the legacy unique index can be recreated. The repo-env fallback now returns a registered repo only when the directory shares its Git metadata, so a separate clone of the same origin no longer receives the registered repo's secrets; external worktrees still resolve. The migration uses a named export.
This commit is contained in:
Chris Scott committed 2026-10-24 11:06:30 -04:00
1 parent e3557f8eec
commit 21c60edd09
6 files changed
+116 -10

No files matched your search

+16 -2
View File
@@ -1210,6 +1210,11 @@ export async function resolveRepoProjectId(openCodeClient: OpenCodeClient, direc
return project.id
}
/**
* Resolves the registered repository a directory belongs to. Beyond the repository's own
* location, a directory is only attributed to a repository that shares its Git metadata, so a
* separate clone of the same origin, whose project id matches, is not mistaken for it.
*/
export async function resolveRepoForDirectory(
database: Database,
directory: string,
@@ -1225,13 +1230,22 @@ export async function resolveRepoForDirectory(
const readyRepos = listRepos(database).filter(
(candidate) => candidate.cloneStatus === 'ready',
)
const candidates: Repo[] = []
for (const candidate of readyRepos) {
const candidateProjectId = await resolveProjectId(candidate.fullPath).catch(
() => null,
)
if (candidateProjectId === projectId) return candidate
if (candidateProjectId === projectId) candidates.push(candidate)
}
return null
if (candidates.length === 0) return null
const mainCheckout = await resolveMainCheckoutPath(directory)
if (!mainCheckout) return null
const canonicalMainCheckout = canonicalPathSync(path.resolve(mainCheckout))
return candidates.find(
(candidate) => canonicalPathSync(path.resolve(candidate.fullPath)) === canonicalMainCheckout,
) ?? null
}
export function resolveRepoOrAssistant(database: Database, id: number): Repo | null {