Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions packages/opencode/src/tests/custody-handle-manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,93 @@ describe('CustodyHandleManifestReader', () => {
})
})

test('reads our accounts while ignoring a foreign block with unknown account keys', async () => {
const foreign = {
provider: 'xai',
serve: 'opencode-claustrum',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Provider filter remains unpinned

Both new reader fixtures give the foreign block a different serve value as well as a different provider. The existing serve selector would therefore still exclude these blocks if provider filtering were accidentally removed, so the tests would not catch that regression. Using a foreign provider with serve: 'anthropic-auth' would independently exercise the provider boundary.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

accounts: [
{
label: 'main',
handle: `ckh_${'H'.repeat(43)}`,
credential_id: 'oauth:xai',
minTtlMs: 7_200_000,
},
],
}
await withManifest(
serialize({
version: 1,
providers: [
foreign,
{
provider: 'anthropic',
shape: 'oauth',
serve: 'anthropic-auth',
accounts: [
{
label: 'work-alt',
handle: `ckh_${'A'.repeat(43)}`,
credential_id: 'oauth:anthropic:work-alt',
},
],
},
],
}),
async (path) => {
const result = await reader(path).read()
expect(result.status).toBe('ready')
if (result.status !== 'ready')
throw new Error('expected ready manifest')
expect(result.manifest.accounts).toEqual([
{
label: 'work-alt',
handle: `ckh_${'A'.repeat(43)}`,
credentialId: 'oauth:anthropic:work-alt',
},
])
expect(result.manifest.corruptLabels).toEqual(new Set())
},
)
})

test('reads our accounts while ignoring hostile foreign provider entries', async () => {
await withManifest(
serialize({
version: 1,
providers: [
{
provider: 'xai',
serve: 'opencode-claustrum',
accounts: 'not-an-array',
},
null,
42,
{ provider: 'xai' },
{
provider: 'anthropic',
shape: 'oauth',
serve: 'anthropic-auth',
accounts: [
{
label: 'work-alt',
handle: `ckh_${'A'.repeat(43)}`,
credential_id: 'oauth:anthropic:work-alt',
},
],
},
],
}),
async (path) => {
const result = await reader(path).read()
expect(result.status).toBe('ready')
if (result.status !== 'ready')
throw new Error('expected ready manifest')
expect(result.manifest.accounts).toHaveLength(1)
expect(result.manifest.corruptLabels).toEqual(new Set())
},
)
})

test('ignores an anthropic block with a foreign serve', async () => {
await withManifest(
withProvider((provider) => {
Expand Down Expand Up @@ -543,6 +630,55 @@ describe('writeCustodyHandleManifestEntry', () => {
})
})

test('preserves a foreign block unknown key byte-identically when writing our account', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Byte identity is overstated

The test parses the file and serializes both objects with the same formatter before comparing them. This checks structure and key order, but cannot detect changes to the foreign block's original whitespace or formatting; the writer also reformats the complete document. Rename the test to describe structural or key-order preservation rather than a byte-level guarantee.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

const foreign = {
provider: 'xai',
serve: 'opencode-claustrum',
accounts: [
{
label: 'main',
handle: `ckh_${'H'.repeat(43)}`,
credential_id: 'oauth:xai',
minTtlMs: 7_200_000,
},
],
}
await withManifest(
serialize({
version: 1,
providers: [
foreign,
{
provider: 'anthropic',
shape: 'oauth',
serve: 'anthropic-auth',
accounts: [],
},
],
}),
async (path) => {
const result = await writeCustodyHandleManifestEntry({
path,
entry: writerEntry,
})
expect(result).toEqual({ status: 'written' })

const output = JSON.parse(await fs.readFile(path, 'utf8')) as {
providers: Array<Record<string, unknown>>
}
const ours = output.providers.find(
(provider) =>
provider.provider === 'anthropic' &&
provider.serve === 'anthropic-auth',
) as { accounts: Array<Record<string, unknown>> }
expect(ours.accounts.map((account) => account.label)).toContain(
writerEntry.label,
)
expect(serialize(output.providers[0])).toBe(serialize(foreign))
},
)
})

test('repairs a missing OAuth shape while retaining all accounts and foreign blocks', async () => {
const existingAccount = {
label: 'existing',
Expand Down
Loading