Skip to content

Commit 1a1ffb0

Browse files
saravmajesticclaude
andcommitted
fix(workspace): report the synced age per account, and tighten two test fixtures
`lastSuccessfulSyncAt` began receiving a marker that carries an account but kept comparing only the workspace, tenant and host — so on a shared tenant the second user was shown the first user's sync time for a snapshot that is not theirs. Its own doc already said "a marker for another workspace or account is not this binding's sync"; it simply had no account to compare. Callers already pass one, since `manage.ts` spreads the scope. Two fixtures, both mine: - the new cross-account snapshot test bound with the default options, so it launched a detached sync and a memory seed that outlive the test; - the re-bind added to the key-rotation test named workspace 1, which is absent from the stub's owner map, so it would have passed for the wrong reason. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent e7a0ba8 commit 1a1ffb0

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎packages/opencode/src/altimate/workspace/skill-sync.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export async function lastSuccessfulSyncAt(
372372
* workspace's snapshot, and would otherwise show A's age under B's name.
373373
* The marker carries its own identity — checking the manifest beside it was
374374
* a second read, and another process could swap the tree between the two. */
375-
binding?: { datamateId: number; tenant: string; apiUrl: string },
375+
binding?: { datamateId: number; tenant: string; apiUrl: string; account: string },
376376
): Promise<number | null> {
377377
// From disk, not from the map. The map is on `globalThis`, which is shared
378378
// across module realms but NOT across threads — and the per-message sync
@@ -390,7 +390,10 @@ export async function lastSuccessfulSyncAt(
390390
if (!marker) return null
391391
if (
392392
binding &&
393-
(marker.datamateId !== binding.datamateId || marker.tenant !== binding.tenant || marker.apiUrl !== binding.apiUrl)
393+
(marker.datamateId !== binding.datamateId ||
394+
marker.tenant !== binding.tenant ||
395+
marker.apiUrl !== binding.apiUrl ||
396+
marker.account !== binding.account)
394397
)
395398
return null
396399
return marker.at

‎packages/opencode/test/altimate/workspace/manage.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,32 @@ const markerFor = (datamateId: number, at: number) =>
970970
JSON.stringify({ at, datamateId, tenant: "acme", apiUrl: "https://api.example.com", account: ACME_ACCOUNT })
971971

972972
describe("the sidebar's skills-synced age", () => {
973+
test("a marker left by another account is not this one's sync", async () => {
974+
// Raised in review. The marker began carrying an account, but the age check
975+
// still compared only the workspace, tenant and host — so on a shared
976+
// tenant the second user was shown the first user's sync time for a
977+
// snapshot that is not theirs.
978+
await bind(projectDir)
979+
const managed = path.join(projectDir, ".altimate-code", "skill", "_workspace")
980+
mkdirSync(managed, { recursive: true })
981+
writeFileSync(path.join(managed, ".manifest.json"), manifestFor(42))
982+
writeFileSync(
983+
path.join(managed, ".synced-at"),
984+
JSON.stringify({
985+
at: Date.now() - 5 * 60_000,
986+
datamateId: 42,
987+
tenant: "acme",
988+
apiUrl: "https://api.example.com",
989+
account: OTHER_ACCOUNT,
990+
}),
991+
)
992+
993+
const report = await status(projectDir)
994+
995+
expect(report.skillsSyncedAt).toBeNull()
996+
})
997+
998+
973999
test("comes from the snapshot on disk, not a per-thread map", async () => {
9741000
// The per-message sync stamps its map in the server worker; the sidebar
9751001
// reads on the main thread, which has its own `globalThis` and so its own

‎packages/opencode/test/altimate/workspace/skill-publish.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,9 @@ describe("the published-id ledger survives a key rotation", () => {
821821
// it and the project re-binds — that is the point of the scoping, and it is
822822
// not what this test is about. The ledger is keyed on the user, so the
823823
// published id must survive the rotation even though the cache did not.
824-
await link(1, "Ops")
824+
// 42, not 1: only the ids in `workspaceOwners` resolve in the stub, so a
825+
// re-bind to an unknown workspace would pass for the wrong reason.
826+
await link(42, "Ops")
825827
requests = []
826828

827829
const report = await publish()

‎packages/opencode/test/altimate/workspace/skill-sync.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ describe("workspace skill sync", () => {
10591059
rmSync(marker)
10601060
mkdirSync(marker) // a directory where the file should be: EISDIR, not ENOENT
10611061

1062-
const asked = { datamateId: 99, tenant: TENANT, apiUrl: API_URL }
1062+
const asked = { datamateId: 99, tenant: TENANT, apiUrl: API_URL, account: FIXTURE_ACCOUNT }
10631063
expect(await lastSuccessfulSyncAt(project, asked)).toBeNull()
10641064
// With no identity asked for, the process's own stamp is still an answer.
10651065
expect(await lastSuccessfulSyncAt(project)).not.toBeNull()
@@ -1828,13 +1828,13 @@ describe("workspace skill sync", () => {
18281828
)
18291829
try {
18301830
// The second user links this project to their own workspace.
1831-
await recordApprovedBinding(project, {
1832-
datamateId: 42,
1833-
datamateName: "ws-42",
1834-
repoRemote: null,
1835-
projectPath: project,
1836-
linkedAt: Date.now(),
1837-
})
1831+
// `seed: false`: this is setup, and the default launches a detached
1832+
// sync and a memory seed that outlive the test.
1833+
await recordApprovedBinding(
1834+
project,
1835+
{ datamateId: 42, datamateName: "ws-42", repoRemote: null, projectPath: project, linkedAt: Date.now() },
1836+
{ seed: false },
1837+
)
18381838
serve({ "pub-2": { "SKILL.md": "two" } })
18391839
await syncSkills(project)
18401840

‎packages/opencode/test/skill/release-v0.12.0-adversarial.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ describe("v0.12.0 adversarial: flattenToolParts against parts the SDK never emit
303303

304304
describe("v0.12.0 adversarial: lastSuccessfulSyncAt against a hand-edited marker", () => {
305305
const MANAGED = path.join(".altimate-code", "skill", "_workspace")
306-
const binding = { datamateId: 7, tenant: "acme", apiUrl: "https://api.example" }
306+
// The marker carries the account that fetched the snapshot, so the identity
307+
// asked about has to name one too.
308+
const binding = { datamateId: 7, tenant: "acme", apiUrl: "https://api.example", account: "acct-7" }
307309

308310
function withMarker(raw: string): string {
309311
const project = fresh("sync")

0 commit comments

Comments
 (0)