Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miakapp/cli",
"version": "4.7.1",
"version": "4.7.2",
"description": "Agent-first Miakapp command line: check, build, publish, activate and roll back home interfaces",
"type": "module",
"engines": {
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,19 @@ export async function publish(
): Promise<{ readonly release: ComponentRelease; readonly pointer: ComponentPointer }> {
const requires = canonicalRequirements(request.requires);
const abi = request.abi ?? COMPONENT_ABI;
const release = await stage(target, artifact, request);
// A build already finalized (by preview, taps or an earlier publish) is
// activated as it is: the control plane refuses to finalize it twice.
const existing = await readRelease(target, artifact.sha256);
if (existing !== undefined
&& (existing.size !== artifact.size
|| existing.abi !== abi
|| !sameRequirements(existing.requires, requires))) {
throw contractError(
'This build is already registered with a different ABI or requirements; '
+ 'change miakapp.yaml back, or rebuild so the digest changes',
);
}
const release = existing ?? await stage(target, artifact, request);
const pointer = await activateRelease(target, {
sha256: artifact.sha256,
expectedGeneration: request.expectedGeneration,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*/
export const PACKAGE_NAME = '@miakapp/cli';

export const CLI_VERSION = '4.7.1';
export const CLI_VERSION = '4.7.2';
23 changes: 23 additions & 0 deletions packages/cli/test/app-publication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ describe('app publication', () => {
expect(host.json()['home_url']).toBeNull();
});

test('activates a build already registered by preview or taps instead of uploading it again', async () => {
const plane = fakeControlPlane({ homeId: HOME_ID, generation: 0 });
const original = plane.fetch;
let uploads = 0;
// Like the real control plane: a digest already registered cannot be uploaded again.
const refusingDuplicates = async (input: string, init: RequestInit) => {
if (init.method === 'POST' && input.endsWith('/component-uploads')) {
uploads += 1;
const body = JSON.parse(String(init.body)) as { sha256: string };
if (plane.releases.has(body.sha256)) {
return new Response(JSON.stringify({ error: { code: 'invalid_artifact', message: 'Component artifact is invalid', retryable: false, request_id: 'r' } }), { status: 422, headers: { 'content-type': 'application/json' } });
}
}
return await original(input, init);
};
const first = testHost({ files: appProject(), fetch: refusingDuplicates, env: { [HOME_KEY_VARIABLE]: homeKey() } });
expect(await run(['publish'], first)).toBe(EXIT_CODE.success);
const again = testHost({ files: appProject(), fetch: refusingDuplicates, env: { [HOME_KEY_VARIABLE]: homeKey() } });
expect(await run(['publish', '--json'], again)).toBe(EXIT_CODE.success);
expect(uploads).toBe(1);
expect(plane.generation).toBe(2);
});

test('refuses a control plane that echoes another ABI', async () => {
const plane = fakeControlPlane({ homeId: HOME_ID, generation: 0 });
const original = plane.fetch;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('publication', () => {
expect(plane.generation).toBe(1);

const methods = plane.requests.map((request) => request.split(' ')[0]);
expect(methods).toEqual(['GET', 'POST', 'POST', 'PUT', 'GET', 'POST', 'POST']);
expect(methods).toEqual(['GET', 'POST', 'GET', 'POST', 'PUT', 'GET', 'POST', 'POST']);
});

test('publish without a Home Key is an authorization failure', async () => {
Expand Down
Loading