diff --git a/packages/cli/package.json b/packages/cli/package.json index 85d90c9..488ac4e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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": { diff --git a/packages/cli/src/publication.ts b/packages/cli/src/publication.ts index a74f269..36cfa36 100644 --- a/packages/cli/src/publication.ts +++ b/packages/cli/src/publication.ts @@ -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, diff --git a/packages/cli/src/version.ts b/packages/cli/src/version.ts index 16d46c7..4c19d9d 100644 --- a/packages/cli/src/version.ts +++ b/packages/cli/src/version.ts @@ -12,4 +12,4 @@ */ export const PACKAGE_NAME = '@miakapp/cli'; -export const CLI_VERSION = '4.7.1'; +export const CLI_VERSION = '4.7.2'; diff --git a/packages/cli/test/app-publication.test.ts b/packages/cli/test/app-publication.test.ts index feda663..657cbaf 100644 --- a/packages/cli/test/app-publication.test.ts +++ b/packages/cli/test/app-publication.test.ts @@ -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; diff --git a/packages/cli/test/main.test.ts b/packages/cli/test/main.test.ts index 736291e..d45672d 100644 --- a/packages/cli/test/main.test.ts +++ b/packages/cli/test/main.test.ts @@ -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 () => {