Skip to content

Commit 86cab61

Browse files
nshkiCopilot
andcommitted
fix(learning): report follow-ups on default migration retry
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
1 parent b6ba8c2 commit 86cab61

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎packages/learning/src/config.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,19 +617,23 @@ export async function migrateScopeOffline(environment, { clock = Date.now, empty
617617
if (empty) throw new LearningError("invalid_input", "This store has already been migrated.")
618618
if (!environment.explicitLegacyScope) {
619619
const { store } = await openLearningStore(environment, { clock })
620+
let redactionFollowUps
620621
try {
621-
const verified = await store.verify({
622+
const context = {
622623
scope: environment.scope,
623624
principal: { kind: "system", id: "system:scope-migration" },
624-
})
625+
}
626+
const verified = await store.verify(context)
625627
if (!verified.ok) throw new LearningError("storage_corrupt", verified.problems.join("; "))
628+
redactionFollowUps = (await store.status(context)).migrationRedactionFollowUps
626629
} finally {
627630
await store.close()
628631
}
629632
return {
630633
file: path.join(environment.dataDirectory, config.memory.provider.file),
631634
sourceProvider: config.memory.migration.sourceProvider,
632635
alreadyMigrated: true,
636+
...(redactionFollowUps ? { redactionFollowUps } : {}),
633637
}
634638
}
635639
}

‎packages/learning/test/scope-migration.test.mjs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,11 @@ it("reports redaction follow-ups on migration and retry", async () => {
939939
destination,
940940
contents: "learnings",
941941
})
942+
const anotherExport = await store.exportRecords(human(secondScope), {
943+
purpose: "instruction",
944+
destination: "private/exports/other.json",
945+
contents: "learnings",
946+
})
942947
const redacted = await store.redactHubComment(human(firstScope), 101)
943948
assert.ok(!redacted.exportsToFollowUp.some((item) => item.id === exported.manifest.id))
944949
const jsonlRepo = checkout("jsonl-redaction-follow-ups")
@@ -1008,6 +1013,13 @@ it("reports redaction follow-ups on migration and retry", async () => {
10081013
(item) => item.id === exported.manifest.id && item.destination === destination,
10091014
),
10101015
)
1016+
assert.ok(
1017+
followUps.exportsToFollowUp.some(
1018+
(item) =>
1019+
item.id === anotherExport.manifest.id &&
1020+
item.destination === "private/exports/other.json",
1021+
),
1022+
)
10111023
const retry = ok(repo, migrate, { failLookup: true })
10121024
assert.deepEqual(retry.redactionFollowUps, followUps)
10131025
const retryText = cli(repo, migrate, { failLookup: true, json: false })
@@ -1059,6 +1071,25 @@ it("reports redaction follow-ups on migration and retry", async () => {
10591071
`Copied migration retry should include ${value}`,
10601072
)
10611073
assert.ok(!copiedRetryText.stdout.includes("\u001b"))
1074+
const defaultRetry = ["migrate-scope", "--offline"]
1075+
const defaultRetryJson = ok(jsonlRepo, defaultRetry, { failLookup: true })
1076+
assert.equal(defaultRetryJson.alreadyMigrated, true)
1077+
assert.deepEqual(defaultRetryJson.redactionFollowUps, followUps)
1078+
const defaultRetryText = cli(jsonlRepo, defaultRetry, { failLookup: true, json: false })
1079+
assert.equal(defaultRetryText.status, 0, defaultRetryText.stderr)
1080+
for (const id of followUps.memoriesNeedingRebuild)
1081+
assert.ok(defaultRetryText.stdout.includes(id), `Default retry should include ${id}`)
1082+
for (const item of followUps.exportsToFollowUp) {
1083+
assert.ok(
1084+
defaultRetryText.stdout.includes(item.id),
1085+
`Default retry should include ${item.id}`,
1086+
)
1087+
assert.ok(
1088+
defaultRetryText.stdout.includes(JSON.stringify(item.destination)),
1089+
`Default retry should include the quoted destination for ${item.id}`,
1090+
)
1091+
}
1092+
assert.ok(!defaultRetryText.stdout.includes("\u001b"))
10621093
assert.deepEqual(
10631094
ok(jsonlRepo, ["status"], { failLookup: true }).migrationRedactionFollowUps,
10641095
followUps,

0 commit comments

Comments
 (0)