fix(research): accept automatic candidate publication lineage (RP16)
This commit is contained in:
parent
e3d6512b8f
commit
cc49f0389c
3 changed files with 157 additions and 2 deletions
|
|
@ -367,6 +367,7 @@ export class ResearchClient {
|
|||
() => undefined
|
||||
);
|
||||
}
|
||||
/** Null selects automatic catalog lineage; receipt retries retain the original parent. */
|
||||
publishVersion(
|
||||
strategyId: string,
|
||||
input: StrategyVersionPackage,
|
||||
|
|
@ -387,7 +388,7 @@ export class ResearchClient {
|
|||
expect(
|
||||
saved.strategyId === strategyId &&
|
||||
saved.origin === 'candidate' &&
|
||||
saved.parentVersionId === parentVersionId &&
|
||||
(parentVersionId === null || saved.parentVersionId === parentVersionId) &&
|
||||
saved.package.artifact.sha256 === pkg.artifact.sha256 &&
|
||||
saved.package.dependencyLock.sha256 === pkg.dependencyLock.sha256
|
||||
);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ describe('authorized research client', () => {
|
|||
const saved = {
|
||||
id: detail.strategyVersionId,
|
||||
strategyId: detail.preview.request.strategy.familyId,
|
||||
ordinal: 2,
|
||||
ordinal: 1,
|
||||
origin: 'candidate',
|
||||
createdBy: agent,
|
||||
parentVersionId: null,
|
||||
|
|
@ -161,6 +161,116 @@ describe('authorized research client', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('automatic publication lineage accepts and retains the server-selected parent', async () => {
|
||||
const detail = ordinary();
|
||||
const pkg = detail.preview.request.strategy.package;
|
||||
const saved = {
|
||||
id: detail.strategyVersionId,
|
||||
strategyId: detail.preview.request.strategy.familyId,
|
||||
ordinal: 2,
|
||||
origin: 'candidate',
|
||||
createdBy: agent,
|
||||
parentVersionId: 'abcdefab-abcd-4bcd-8bcd-000000000002',
|
||||
package: pkg,
|
||||
};
|
||||
const publication = client(() => Response.json({ version: saved }, { status: 201 }));
|
||||
const implicit = await publication.value.publishVersion(saved.strategyId, pkg, requestKey);
|
||||
const explicitNull = await publication.value.publishVersion(
|
||||
saved.strategyId,
|
||||
pkg,
|
||||
requestKey,
|
||||
null
|
||||
);
|
||||
expect(implicit).toMatchObject({ id: saved.id, parentVersionId: saved.parentVersionId });
|
||||
expect(explicitNull).toEqual(implicit);
|
||||
expect(publication.calls).toHaveLength(2);
|
||||
expect(publication.calls[0]!.body).toEqual({ package: pkg, parentVersionId: null });
|
||||
expect(publication.calls[1]!.init.body).toBe(publication.calls[0]!.init.body!);
|
||||
});
|
||||
|
||||
test('automatic lineage receipt retries retain the original key/body after a newer publication', async () => {
|
||||
const detail = ordinary();
|
||||
const pkg = detail.preview.request.strategy.package;
|
||||
const second = {
|
||||
id: detail.strategyVersionId,
|
||||
strategyId: detail.preview.request.strategy.familyId,
|
||||
ordinal: 2,
|
||||
origin: 'candidate',
|
||||
createdBy: agent,
|
||||
parentVersionId: 'abcdefab-abcd-4bcd-8bcd-000000000002',
|
||||
package: pkg,
|
||||
};
|
||||
const third = {
|
||||
...second,
|
||||
id: 'abcdefab-abcd-4bcd-8bcd-000000000003',
|
||||
ordinal: 3,
|
||||
parentVersionId: second.id,
|
||||
};
|
||||
const publication = client((_call, index) => {
|
||||
if (index === 0) {
|
||||
throw new Error('Response lost after the second version committed');
|
||||
}
|
||||
return Response.json({ version: index === 1 ? third : second }, { status: 201 });
|
||||
});
|
||||
await expect(
|
||||
publication.value.publishVersion(second.strategyId, pkg, requestKey)
|
||||
).rejects.toMatchObject({ uncertain: true });
|
||||
expect(publication.calls).toHaveLength(1);
|
||||
expect(
|
||||
await publication.value.publishVersion(second.strategyId, pkg, `${requestKey}:new`)
|
||||
).toMatchObject({ id: third.id, parentVersionId: second.id });
|
||||
expect(
|
||||
await publication.value.publishVersion(second.strategyId, pkg, requestKey)
|
||||
).toMatchObject({ id: second.id, parentVersionId: second.parentVersionId });
|
||||
expect(publication.calls).toHaveLength(3);
|
||||
expect(publication.calls.every(call => call.init.method === 'POST')).toBeTrue();
|
||||
expect(publication.calls[2]!.init.body).toBe(publication.calls[0]!.init.body!);
|
||||
expect(publication.calls[2]!.body).toEqual({ package: pkg, parentVersionId: null });
|
||||
for (const index of [0, 2]) {
|
||||
expect(new Headers(publication.calls[index]!.init.headers).get('idempotency-key')).toBe(
|
||||
requestKey
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('publication still rejects wrong explicit lineage, malformed parents, family, origin and hashes', async () => {
|
||||
const detail = ordinary();
|
||||
const pkg = detail.preview.request.strategy.package;
|
||||
const saved = {
|
||||
id: detail.strategyVersionId,
|
||||
strategyId: detail.preview.request.strategy.familyId,
|
||||
ordinal: 2,
|
||||
origin: 'candidate',
|
||||
createdBy: agent,
|
||||
parentVersionId: 'abcdefab-abcd-4bcd-8bcd-000000000002',
|
||||
package: pkg,
|
||||
};
|
||||
const explicit = client(() => Response.json({ version: saved }, { status: 201 }));
|
||||
await expect(
|
||||
explicit.value.publishVersion(saved.strategyId, pkg, requestKey, saved.id)
|
||||
).rejects.toMatchObject({ uncertain: true });
|
||||
expect(explicit.calls).toHaveLength(1);
|
||||
expect(explicit.calls[0]!.body).toEqual({ package: pkg, parentVersionId: saved.id });
|
||||
for (const invalid of [
|
||||
{ ...saved, parentVersionId: 'not-a-version-id' },
|
||||
{ ...saved, parentVersionId: 2 },
|
||||
{ ...saved, parentVersionId: undefined },
|
||||
{ ...saved, strategyId: 'abcdefab-abcd-4bcd-8bcd-000000000003' },
|
||||
{ ...saved, origin: 'builtin' },
|
||||
{ ...saved, package: { ...pkg, artifact: { ...pkg.artifact, sha256: 'f'.repeat(64) } } },
|
||||
{
|
||||
...saved,
|
||||
package: { ...pkg, dependencyLock: { ...pkg.dependencyLock, sha256: 'f'.repeat(64) } },
|
||||
},
|
||||
]) {
|
||||
const rejected = client(() => Response.json({ version: invalid }, { status: 201 }));
|
||||
await expect(
|
||||
rejected.value.publishVersion(saved.strategyId, pkg, requestKey)
|
||||
).rejects.toMatchObject({ uncertain: true });
|
||||
expect(rejected.calls).toHaveLength(1);
|
||||
}
|
||||
});
|
||||
|
||||
test('normalizes uppercase identities before captures and binds cancellation and publication receipts', async () => {
|
||||
const detail = ordinary();
|
||||
detail.id = 'abcdefab-abcd-4bcd-8bcd-abcdefabcdef';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue