Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

feat(ci): accept branch-selectable auto-numbered Motion candidates

罗高b66936c8bfa3
diff --git a/.github/scripts/motion-release.mjs b/.github/scripts/motion-release.mjs
index fa8561de..af4a41e7 100644
--- a/.github/scripts/motion-release.mjs
+++ b/.github/scripts/motion-release.mjs
@@ -7,7 +7,7 @@ import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { runFile, sha256, writeJSON } from '../../scripts/runtime-assets.mjs';
-import { checkReleaseVersion, compareReleaseVersions } from '../../scripts/release-version.mjs';
+import { checkReleaseVersion, compareReleaseVersions, testVersion } from '../../scripts/release-version.mjs';
import { generateInstallGuide } from '../../scripts/install-guide.mjs';
import { publishGuide, storagePlan } from './publish-install-guide.mjs';
import { scanPackage, scanSource } from './motion-scan.mjs';
@@ -17,6 +17,7 @@ export const candidateWorkflow = '.github/workflows/motion-candidate.yml';
export const publicationWorkflow = '.github/workflows/motion-publish-test.yml';
export const recoveryWorkflow = '.github/workflows/motion-publication-recovery.yml';
export const candidateJobName = 'Build immutable candidate';
+const candidateRefs = ['refs/heads/main', 'refs/heads/feature/motion'];
const exec = promisify(execFile), hashPattern = /^[a-f0-9]{64}$/;
const json = async file => JSON.parse(await readFile(file, 'utf8'));
const integrity = bytes => 'sha512-' + createHash('sha512').update(bytes).digest('base64');
@@ -35,10 +36,17 @@ export function releaseInputs(env = process.env) {
return { action: env.MOTION_RELEASE_ACTION, accepted: true, version: env.MOTION_VERSION, expectedSHA256: env.MOTION_EXPECTED_SHA256 };
}
-export async function resolveSource(control, requested, version, run = runFile) {
+export async function resolveCandidate(control, requested, version, env = process.env, run = runFile) {
const commit = requested || (await run('git', ['rev-parse', 'refs/remotes/origin/feature/motion'], { cwd: control })).trim();
+ assert.match(commit, /^[a-f0-9]{40}$/, 'Use a full immutable source SHA');
+ if (!version) {
+ assert(/^[1-9]\d*$/.test(env.GITHUB_RUN_ATTEMPT || ''), 'A positive GitHub run attempt is required');
+ // main still contains the legacy application; read the frozen Motion source instead.
+ const source = JSON.parse(await run('git', ['show', `${commit}:package.json`], { cwd: control }));
+ version = testVersion(source.version, env.GITHUB_RUN_ID, env.GITHUB_RUN_ATTEMPT);
+ }
await validateSource(control, commit, version, run);
- return commit;
+ return { commit, version };
}
export async function validateSource(control, commit, version, run = runFile) {
@@ -53,7 +61,8 @@ export async function sealCandidate(build, output, source, env = process.env) {
assert.equal(manifest.commit, env.MOTION_SOURCE_SHA); assert.equal(manifest.version, env.MOTION_VERSION);
assert(manifest.version.includes('-test.') && manifest.templateEnvironment === 'dev', 'Test candidates require DEV template defaults');
assert.match(env.GITHUB_SHA || '', /^[a-f0-9]{40}$/);
- assert.equal(env.GITHUB_WORKFLOW_REF, `${repository}/${candidateWorkflow}@refs/heads/main`);
+ const workflowRef = candidateRefs.find(ref => env.GITHUB_WORKFLOW_REF === `${repository}/${candidateWorkflow}@${ref}`);
+ assert(workflowRef, 'Build candidates only from main or feature/motion');
assert(/^[1-9]\d*$/.test(env.GITHUB_RUN_ID || '') && /^[1-9]\d*$/.test(env.GITHUB_RUN_ATTEMPT || ''));
const filename = manifest.installer.url.replace(/^\.\//, '');
assert.equal(filename, `openmotion-app-${manifest.version}.tgz`);
@@ -79,7 +88,7 @@ export async function sealCandidate(build, output, source, env = process.env) {
const files = Object.fromEntries(await Promise.all(names.map(async name => [name, await sha256(path.join(output, name))])));
const candidate = { schemaVersion: 2, kind: 'motion-candidate', packageName: guide.packageName, version: guide.version,
sourceCommit: guide.commit, tgz: filename, tgzSHA256: files[filename], integrity: integrity(await readFile(path.join(output, filename))), files,
- workflow: { repository, path: candidateWorkflow, ref: 'refs/heads/main', sha: env.GITHUB_SHA,
+ workflow: { repository, path: candidateWorkflow, ref: workflowRef, sha: env.GITHUB_SHA,
runId: Number(env.GITHUB_RUN_ID), attempt: Number(env.GITHUB_RUN_ATTEMPT) },
createdAt: new Date().toISOString(), acceptance: 'not-performed' };
await writeJSON(path.join(output, 'candidate.json'), candidate);
@@ -87,7 +96,7 @@ export async function sealCandidate(build, output, source, env = process.env) {
}
export function validateRun(run, artifact, version) {
- assert.equal(run.event, 'workflow_dispatch'); assert.equal(run.head_branch, 'main');
+ assert.equal(run.event, 'workflow_dispatch'); assert(candidateRefs.includes(`refs/heads/${run.head_branch}`), 'Untrusted candidate branch');
assert.equal(run.head_repository?.full_name, repository);
assert.equal(run.status, 'completed'); assert.equal(run.conclusion, 'success', 'Candidate build must finish successfully');
assert.equal(run.path.split('@')[0], candidateWorkflow, 'Candidate must come from the registered build workflow');
@@ -140,7 +149,9 @@ export async function verifyCandidate(directory, expectedSHA256, run) {
checkReleaseVersion(candidate.version); assert(candidate.version.includes('-test.'));
assert.equal(candidate.tgz, `openmotion-app-${candidate.version}.tgz`); assert.equal(candidate.tgzSHA256, expectedSHA256);
assert.match(expectedSHA256, hashPattern); assert.match(candidate.sourceCommit, /^[a-f0-9]{40}$/);
- assert.deepEqual(candidate.workflow, { repository, path: candidateWorkflow, ref: 'refs/heads/main', sha: run.head_sha, runId: run.id, attempt: run.run_attempt });
+ const ref = `refs/heads/${run.head_branch || 'main'}`; // Older main-only receipts omitted the branch.
+ assert(candidateRefs.includes(ref), 'Untrusted candidate branch');
+ assert.deepEqual(candidate.workflow, { repository, path: candidateWorkflow, ref, sha: run.head_sha, runId: run.id, attempt: run.run_attempt });
const names = [candidate.tgz, 'release-npm.json', 'source-scan.json', 'package-scan.json', 'install.md', 'install-record.json', 'acceptance.md', 'candidate-install.md'];
assert.deepEqual(Object.keys(candidate.files).sort(), names.sort());
for (const name of names) assert.equal(await sha256(path.join(directory, name)), candidate.files[name], 'Candidate file changed: ' + name);
@@ -160,7 +171,7 @@ export async function verifyCandidate(directory, expectedSHA256, run) {
export async function verifyDownloaded(directory, expectedSHA256, version) {
const provenance = await json(path.join(directory, 'provenance.json'));
- const candidate = await verifyCandidate(directory, expectedSHA256, { head_sha: provenance.head_sha, id: provenance.runId, run_attempt: provenance.attempt });
+ const candidate = await verifyCandidate(directory, expectedSHA256, { head_branch: provenance.head_branch, head_sha: provenance.head_sha, id: provenance.runId, run_attempt: provenance.attempt });
if (version) assert.equal(candidate.version, version, 'Candidate version differs from the accepted version');
return candidate;
}
@@ -215,7 +226,7 @@ export async function downloadCandidate(version, directory, expectedSHA256, fetc
}
const candidate = await verifyCandidate(directory, expectedSHA256 || (await json(path.join(directory, 'candidate.json'))).tgzSHA256, run);
assert.equal(candidate.version, version, 'Artifact version differs from the accepted version');
- await writeJSON(path.join(directory, 'provenance.json'), { runId: run.id, attempt: run.run_attempt, head_sha: run.head_sha, artifactId: artifact.id, digest: artifact.digest });
+ await writeJSON(path.join(directory, 'provenance.json'), { runId: run.id, attempt: run.run_attempt, head_branch: run.head_branch, head_sha: run.head_sha, artifactId: artifact.id, digest: artifact.digest });
return candidate;
} finally { await rm(work, { recursive: true, force: true }); }
}
@@ -333,9 +344,9 @@ export async function archiveRelease(directory, inputs, config, { run = runFile,
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const [command, directory, extra, final] = process.argv.slice(2);
if (command === 'source') {
- const commit = await resolveSource(directory, process.env.MOTION_SOURCE_SHA, process.env.MOTION_VERSION);
+ const { commit, version } = await resolveCandidate(directory, process.env.MOTION_SOURCE_SHA, process.env.MOTION_VERSION);
const { appendFile } = await import('node:fs/promises');
- await appendFile(process.env.GITHUB_OUTPUT, `source_sha=${commit}\n`);
+ await appendFile(process.env.GITHUB_OUTPUT, `source_sha=${commit}\nversion=${version}\n`);
}
else if (command === 'seal') await sealCandidate(directory, extra, final);
else {
diff --git a/.github/workflows/motion-candidate.yml b/.github/workflows/motion-candidate.yml
index 02a7fc0c..55bf487b 100644
--- a/.github/workflows/motion-candidate.yml
+++ b/.github/workflows/motion-candidate.yml
@@ -1,13 +1,14 @@
name: Motion candidate build
-run-name: Motion candidate · ${{ inputs.version }}
+run-name: Motion candidate · ${{ inputs.version || 'auto' }}
on:
workflow_dispatch:
inputs:
version:
- description: 'New test version, e.g. 0.6.4-test.7; build and retain only, never publish'
+ description: 'Optional override; empty uses next Motion patch-test.<run ID>.<attempt>; build only'
type: string
- required: true
+ required: false
+ default: ''
source_sha:
description: 'Optional reviewed full SHA integrated into feature/motion; empty freezes its current head'
type: string
@@ -20,7 +21,7 @@ permissions:
jobs:
candidate:
name: Build immutable candidate
- if: github.repository == 'nexu-io/html-anything' && github.ref == 'refs/heads/main'
+ if: github.repository == 'nexu-io/html-anything' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/motion')
runs-on: ubuntu-24.04
timeout-minutes: 45
env:
@@ -76,6 +77,7 @@ jobs:
- name: Build the final DEV application tgz once and scan both archives
env:
MOTION_SOURCE_SHA: ${{ steps.source.outputs.source_sha }}
+ MOTION_VERSION: ${{ steps.source.outputs.version }}
run: |
node source/scripts/package-npm.mjs "$RUNNER_TEMP/build" "$MOTION_VERSION" --template-env=dev
cp "$RUNNER_TEMP/source-scan.json" "$RUNNER_TEMP/build/source-scan.json"
@@ -85,7 +87,7 @@ jobs:
id: artifact
uses: actions/[email protected]
with:
- name: motion-candidate-${{ inputs.version }}
+ name: motion-candidate-${{ steps.source.outputs.version }}
path: ${{ runner.temp }}/candidate/
retention-days: 30
if-no-files-found: error
diff --git a/AGENTS.md b/AGENTS.md
index e6e59f50..d56d1a48 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -16,7 +16,7 @@ This version has breaking changes — APIs, conventions, and file structure may
## Motion release controls
- Motion application development remains on `feature/motion`. Registering manual workflows on `main` does not move the application or authorize publication.
-- After registration is merged, manual release jobs execute the trusted controls from `main` and select integrated application source from `feature/motion`. Before registration, those manual entries are not available on the default branch.
+- Manual candidate builds may run from `feature/motion` or `main`, with an optional version override; blank versions use the frozen Motion source baseline and GitHub run ID/attempt. Publication and recovery still execute trusted controls from `main`. Application source must be integrated into `feature/motion`; arbitrary branches cannot supply candidates.
- Use Node 26.11.1 for control checks: `node --test tests/release-workflows.test.mjs tests/release-scan.test.mjs tests/install-guide.test.ts`. These tests need no workspace dependency installation and simulate publication services.
- New test candidates embed DEV defaults. npm publication uses `candidate` first; only matching successful Mac/Windows native reports permit the separate promotion job to advance `test`. Stable publication, `latest` promotion and Skills platform distribution remain out of scope.
- Follow [activation and operation](docs/motion-release-activation.md). Keep completed acceptance evidence private; do not merge or publish without the task's explicit authorization.
diff --git a/docs/motion-release-activation.md b/docs/motion-release-activation.md
index dc1dff0e..17197461 100644
--- a/docs/motion-release-activation.md
+++ b/docs/motion-release-activation.md
@@ -6,7 +6,9 @@ This branch retains the legacy HTML Anything application. The Motion application
The three manual workflows, their runtime helpers, installation/acceptance templates and deterministic tests were initially copied without modification from reviewed PR [#214](https://github.com/nexu-io/html-anything/pull/214), source commit `de45dadea282214762c7b3123cea7e6b1044f26f`. The test-channel follow-up copies the same 18 shared control files byte-for-byte from Motion commit `94d15d656eb085f98067867502418bb99c7de0e9` and updates this control set to require DEV candidates and defer npm test promotion until native checks pass. No application business logic or private Git history is imported; shared runtime helpers and tests are included as control dependencies. The extra `Motion release controls` CI job runs only syntax checks and simulated-service tests with read-only permissions; the legacy CI commands and permissions are preserved. Its runner is pinned to Ubuntu 24.04 because the locked Playwright cannot install browsers on the Ubuntu 26.04 image now selected by ubuntu-latest.
-GitHub requires a manual workflow to exist on the default branch before its Run workflow entry is available. After registration, our controls additionally require execution from `main`; they fetch the Motion application from a reviewed commit integrated into `feature/motion`. See [GitHub manual workflows](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/manually-run-a-workflow).
+The branch-selection/automatic-numbering follow-up copies the same shared control set from Motion commit `a664ffeb823216fe03db2f576dbceac2cf5bb3fd`. Empty versions derive from that candidate's frozen Motion source, never from the legacy main package version. Source manifests are not bumped by a build. Both matching PRs must be integrated before accepting feature/motion-produced candidates for publication.
+
+GitHub requires a manual workflow to exist on the default branch before its Run workflow entry is available. Candidate builds now allow `feature/motion` or `main`; publication and recovery still require execution from `main`. They fetch the Motion application from a reviewed commit integrated into `feature/motion`. See [GitHub manual workflows](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/manually-run-a-workflow).
## Activation order
@@ -19,16 +21,16 @@ These are separate actions. Preparing or merging the registration does not autho
## Daily operation
-1. **Build:** Actions → Motion candidate build → Run workflow → select `main`. Enter a new `X.Y.Z-test.N` version; normally leave `source_sha` empty to freeze the latest `feature/motion` head once. A supplied full SHA must already be integrated into that branch. The build checks/scans source and archives, and retains the exact candidate for 30 days without npm OIDC or R2 credentials.
+1. **Build:** Actions → Motion candidate build → Run workflow → select `feature/motion` (`main` also works). Leave version empty to generate the next Motion source patch plus `-test.<GitHub run ID>.<attempt>`, e.g. `0.6.4-test.42812345678.1` from source `0.6.3`; an explicit new test-version override remains available. Output metadata is stamped without changing source manifests. Read the resolved version from the successful summary; normally leave `source_sha` empty to freeze the latest `feature/motion` head once. A supplied full SHA must already be integrated into that branch. The build checks/scans source and archives, and retains the exact candidate for 30 days without npm OIDC or R2 credentials.
2. **Download and accept:** Download `motion-candidate-<version>` from the successful run, extract it and give its directory to the Agent: “Follow candidate-install.md, verify candidate.json and the local tgz hash, install the exact local package with an isolated host profile, application home, data and Skills directories, complete prepare, and record actual results in a private copy of acceptance.md. Mark unrun checks NOT RUN. Do not publish.” Keep actual host loading, template/edit/export checks, real Agent creation and human playback separate. New public test software defaults to DEV templates; existing prod test versions retain their original defaults. The package exposes DEV routing configuration without private catalog snapshots or credentials. DEV network access/authentication is still required.
-3. **Publish:** Only after acceptance, Actions → Motion test publication → Run workflow → select `main`. Enter the exact accepted version and confirm `accepted`. This is the publication authorization, with no later independent approval dialog. Candidate provenance/hashes and scans are checked again; only the accepted tgz is published under npm `candidate`, then anonymously checked on Mac/Windows. A separate npm-OIDC-only job verifies both reports, their exact identity and installed DEV defaults, advances `test`, and reads the tag back. Only then does the credential-isolated R2 job archive snapshots and advance the default guide.
+3. **Publish:** Only after acceptance, Actions → Motion test publication → Run workflow → select `main`. Enter the exact accepted version from the build summary and confirm `accepted`; publication never generates a new version. This is the publication authorization, with no later independent approval dialog. Candidate provenance/hashes and scans are checked again; only the accepted tgz is published under npm `candidate`, then anonymously checked on Mac/Windows. A separate npm-OIDC-only job verifies both reports, their exact identity and installed DEV defaults, advances `test`, and reads the tag back. Only then does the credential-isolated R2 job archive snapshots and advance the default guide.
Before npm publication, use the candidate's **local** `candidate-install.md`, not the sibling registry `install.md`. After publication, the moving test guide is `https://releases.open-design.ai/open-motion/dev/install.md`; the immutable guide is `/open-motion/dev/<version>/install.md`. Stable publication, npm `latest` promotion and Skills platform/marketplace upload are not implemented by these controls. Five Skills are bundled and installed locally; that is not platform publication.
## Risk and recovery boundaries
- Registration is a capability change: users who can dispatch the trusted publication workflow can confirm and start a public release. There is no independent approval gate at this stage. Protect workflow edits and restrict operational access; the operator confirmation records intent, not proof of private testing.
-- Builds do not publish. The publication form defaults acceptance to false and rejects missing, expired, ambiguous or untrusted candidates, changed bytes and unintegrated source. Do not rebuild a published version or guess among duplicate candidate artifacts.
+- Candidate workflows and control changes on both allowed branches require review. The producer branch/SHA is recorded and verified against GitHub run metadata; an arbitrary branch is rejected. Builds do not publish. The publication form defaults acceptance to false and rejects missing, expired, ambiguous or untrusted candidates, changed bytes and unintegrated source. Do not rebuild a published version or guess among duplicate candidate artifacts.
- npm publication cannot be rolled back atomically with later checks. The exact candidate and `candidate` tag are public before native verification. If either native check fails, `test` and the default guide remain unchanged. R2 failure after successful native/tag checks may leave `test` on the verified new version and the default guide on the prior one; this is not an atomic npm/R2 transaction. Inspect `test-promotion.json` and retained attempt records. Never use npm dist-tag as a dry-run against the real registry. Inspect retained records before using Re-run failed jobs; those retries reuse successful producer artifact IDs and never rebuild the candidate.
- Motion snapshot recovery writes versioned R2 snapshots for an already published identical npm package; it does not build, publish npm, move tags or access the default guide. Channel rollback and client/data recovery require separate decisions.
- A single publication concurrency group and version/ETag checks protect channel promotion. Operate one release at a time; GitHub does not provide a durable FIFO queue.
diff --git a/scripts/release-version.mjs b/scripts/release-version.mjs
index d64755f7..d2aad7ec 100644
--- a/scripts/release-version.mjs
+++ b/scripts/release-version.mjs
@@ -1,5 +1,12 @@
import assert from 'node:assert/strict';
+export function testVersion(base, run, attempt = '1') {
+ assert(/^\d+\.\d+\.\d+$/.test(base), 'Source version must be MAJOR.MINOR.PATCH');
+ assert(/^[1-9]\d*$/.test(String(run)) && /^[1-9]\d*$/.test(String(attempt)), 'Use positive run and attempt numbers');
+ const [major, minor, patch] = base.split('.').map(Number);
+ return `${major}.${minor}.${patch + 1}-test.${run}.${attempt}`;
+}
+
export function checkReleaseVersion(version) {
assert.match(version, /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-test\.[1-9]\d*(?:\.[1-9]\d*)*)?$/, 'Use MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH-test.N[.N]');
}
diff --git a/tests/release-fixture.mjs b/tests/release-fixture.mjs
index 0024f91a..8a45aece 100644
--- a/tests/release-fixture.mjs
+++ b/tests/release-fixture.mjs
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
import { runFile, sha256, writeJSON } from '../scripts/runtime-assets.mjs';
import { sealCandidate, repository, candidateWorkflow, publicationWorkflow, authorizationReceipt, platformReports } from '../.github/scripts/motion-release.mjs';
-export async function candidateFixture(t) {
+export async function candidateFixture(t, branch = 'main') {
const work = await mkdtemp(path.join(os.tmpdir(), 'motion-release-test-'));
t.after(() => rm(work, { recursive: true, force: true }));
const root = fileURLToPath(new URL('../', import.meta.url)), build = path.join(work, 'build'), directory = path.join(work, 'candidate');
@@ -28,9 +28,9 @@ export async function candidateFixture(t) {
await writeJSON(path.join(build, 'release-npm.json'), { ...manifest, installer: { url: './' + path.basename(tgz), sha256: await sha256(tgz) } });
for (const name of ['source-scan.json', 'package-scan.json']) await writeJSON(path.join(build, name), { status: 'passed' });
const env = { MOTION_SOURCE_SHA: commit, MOTION_VERSION: version, GITHUB_SHA: 'b'.repeat(40),
- GITHUB_WORKFLOW_REF: `${repository}/${candidateWorkflow}@refs/heads/main`, GITHUB_RUN_ID: '123', GITHUB_RUN_ATTEMPT: '1' };
+ GITHUB_WORKFLOW_REF: `${repository}/${candidateWorkflow}@refs/heads/${branch}`, GITHUB_RUN_ID: '123', GITHUB_RUN_ATTEMPT: '1' };
const candidate = await sealCandidate(build, directory, root, env);
- const provenance = { head_sha: env.GITHUB_SHA, runId: 123, attempt: 1 };
+ const provenance = { head_branch: branch, head_sha: env.GITHUB_SHA, runId: 123, attempt: 1 };
await writeJSON(path.join(directory, 'provenance.json'), provenance);
const inputs = { action: 'publish-test', version, accepted: true, expectedSHA256: candidate.tgzSHA256 };
const publicationEnv = { GITHUB_REPOSITORY: repository, GITHUB_EVENT_NAME: 'workflow_dispatch', GITHUB_REF: 'refs/heads/main',
diff --git a/tests/release-workflows.test.mjs b/tests/release-workflows.test.mjs
index c20a86f1..3aea70d3 100644
--- a/tests/release-workflows.test.mjs
+++ b/tests/release-workflows.test.mjs
@@ -1,10 +1,12 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { readFile, writeFile, rm } from 'node:fs/promises';
+import { readFile, writeFile, rm, mkdtemp } from 'node:fs/promises';
+import os from 'node:os';
+import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { createHash } from 'node:crypto';
import { candidateFixture } from './release-fixture.mjs';
-import { releaseInputs, resolveSource, validateSource, validateRun, verifyDownloaded, downloadCandidate, publishNpm, promoteTest, archiveRelease, repository, candidateWorkflow, recoveryWorkflow, publicationWorkflow, candidateJobName, findCandidate, authorizationReceipt, recordAuthorization } from '../.github/scripts/motion-release.mjs';
+import { releaseInputs, resolveCandidate, validateSource, validateRun, verifyDownloaded, downloadCandidate, publishNpm, promoteTest, archiveRelease, repository, candidateWorkflow, recoveryWorkflow, publicationWorkflow, candidateJobName, findCandidate, authorizationReceipt, recordAuthorization } from '../.github/scripts/motion-release.mjs';
import { compareReleaseVersions } from '../scripts/release-version.mjs';
import { consumerEnvironment } from '../.github/scripts/motion-registry-smoke.mjs';
import { runFile } from '../scripts/runtime-assets.mjs';
@@ -24,13 +26,45 @@ test('manual entry and source selection reject untrusted callers, mutable refs a
await validateSource('.', 'a'.repeat(40), '0.6.4-test.7', async (_, args) => { called = true; assert(args.includes('refs/remotes/origin/feature/motion')); }); assert(called);
for (const [sha, version] of [['main', '0.6.4-test.7'], ['a'.repeat(40), '0.6.4'], ['a'.repeat(40), '0.6.4-test.0']]) await assert.rejects(validateSource('.', sha, version, async () => { throw Error('must not run'); }));
await assert.rejects(validateSource('.', 'a'.repeat(40), '0.6.4-test.7', async () => { throw Error('not integrated'); }), /not integrated/);
- const resolved = await resolveSource('.', '', '0.6.4-test.7', async (_, args) => args[0] === 'rev-parse' ? 'a'.repeat(40) + '\n' : '');
- assert.equal(resolved, 'a'.repeat(40));
+ const resolved = await resolveCandidate('.', '', '0.6.4-test.7', {}, async (_, args) => args[0] === 'rev-parse' ? 'a'.repeat(40) + '\n' : '');
+ assert.deepEqual(resolved, { commit: 'a'.repeat(40), version: '0.6.4-test.7' });
+ await assert.rejects(resolveCandidate('.', 'main', '', {}, async () => { throw Error('must not run'); }), /immutable/);
+ for (const env of [{}, { GITHUB_RUN_ID: '42812345678', GITHUB_RUN_ATTEMPT: '0' }, { GITHUB_RUN_ID: 'bad', GITHUB_RUN_ATTEMPT: '1' }]) {
+ await assert.rejects(resolveCandidate('.', 'a'.repeat(40), '', env, async () => JSON.stringify({ version: '0.6.3' })), /positive/);
+ }
+});
+
+test('candidate CLI numbers the frozen Motion source, not the legacy control checkout, and preserves overrides', async t => {
+ const directory = await mkdtemp(path.join(os.tmpdir(), 'motion-version-'));
+ t.after(() => rm(directory, { recursive: true, force: true }));
+ const git = (...args) => runFile('git', args, { cwd: directory });
+ await git('init', '-q');
+ await writeFile(path.join(directory, 'package.json'), JSON.stringify({ version: '0.6.3' }));
+ await git('add', 'package.json');
+ await git('-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'commit.gpgsign=false', 'commit', '-qm', 'Motion source');
+ const commit = (await git('rev-parse', 'HEAD')).trim();
+ await git('update-ref', 'refs/remotes/origin/feature/motion', commit);
+ await writeFile(path.join(directory, 'package.json'), JSON.stringify({ version: '0.1.0' }));
+ const output = path.join(directory, 'output'), script = fileURLToPath(new URL('../.github/scripts/motion-release.mjs', import.meta.url));
+ for (const [source, version, run, attempt, expected] of [
+ ['', '', '42812345678', '1', '0.6.4-test.42812345678.1'],
+ [commit, '', '42812345678', '2', '0.6.4-test.42812345678.2'],
+ ['', '', '42812345679', '1', '0.6.4-test.42812345679.1'],
+ [commit, '0.6.5-test.1', '', '', '0.6.5-test.1'],
+ ]) {
+ await writeFile(output, '');
+ await runFile(process.execPath, [script, 'source', directory], { env: { ...process.env, GITHUB_OUTPUT: output,
+ MOTION_SOURCE_SHA: source, MOTION_VERSION: version, GITHUB_RUN_ID: run, GITHUB_RUN_ATTEMPT: attempt } });
+ assert.equal(await readFile(output, 'utf8'), `source_sha=${commit}\nversion=${expected}\n`);
+ assert(compareReleaseVersions(expected, '0.6.4-test.6') > 0);
+ }
+ assert.equal(JSON.parse(await readFile(path.join(directory, 'package.json'))).version, '0.1.0');
});
test('only a completed successful registered candidate build can supply a version', () => {
validateRun(origin, artifact, '0.6.4-test.99');
- for (const patch of [{ event: 'pull_request' }, { head_branch: 'feature/motion' }, { path: '.github/workflows/other.yml' }, { head_repository: { full_name: 'fork/repo' } }, { status: 'in_progress' }, { conclusion: 'failure' }]) assert.throws(() => validateRun({ ...origin, ...patch }, artifact, '0.6.4-test.99'));
+ validateRun({ ...origin, head_branch: 'feature/motion' }, artifact, '0.6.4-test.99');
+ for (const patch of [{ event: 'pull_request' }, { head_branch: 'codex/unreviewed' }, { head_branch: 'legacy' }, { path: '.github/workflows/other.yml' }, { head_repository: { full_name: 'fork/repo' } }, { status: 'in_progress' }, { conclusion: 'failure' }]) assert.throws(() => validateRun({ ...origin, ...patch }, artifact, '0.6.4-test.99'));
for (const patch of [{ expired: true }, { name: 'motion-candidate-0.6.4-test.100' }, { digest: null }, { workflow_run: { id: 999 } }]) assert.throws(() => validateRun(origin, { ...artifact, ...patch }, '0.6.4-test.99'));
});
@@ -83,23 +117,36 @@ test('the sealed candidate detects tgz, guide, identity and provenance tampering
await assert.rejects(verifyDownloaded(directory, candidate.tgzSHA256));
});
-test('artifact download verifies GitHub ZIP digest and does not forward the credential to the signed URL', async t => {
- const f = await candidateFixture(t), zip = path.join(f.work, 'candidate.zip');
+for (const branch of ['main', 'feature/motion']) test(`artifact download binds ${branch} provenance and does not forward credentials to signed URLs`, async t => {
+ const f = await candidateFixture(t, branch), zip = path.join(f.work, 'candidate.zip');
+ const producer = { ...origin, head_branch: branch };
await runFile('zip', ['-j', zip, ...['candidate.json', ...Object.keys(f.candidate.files)].map(name => path.join(f.directory, name))]);
const bytes = await readFile(zip), digest = 'sha256:' + createHash('sha256').update(bytes).digest('hex');
const fetcher = async (url, options) => {
const value = String(url);
- if (value.endsWith('/actions/runs/123')) return Response.json(origin);
+ if (value.endsWith('/actions/runs/123')) return Response.json(producer);
if (value.includes('/artifacts?')) return Response.json({ total_count: 1, artifacts: [{ ...artifact, digest, size_in_bytes: bytes.length }] });
if (value.endsWith('/456/zip')) return new Response(null, { status: 302, headers: { location: 'https://signed.example.invalid/candidate' } });
assert.equal(value, 'https://signed.example.invalid/candidate'); assert.equal(options.headers, undefined);
return new Response(bytes);
};
assert.equal((await downloadCandidate(f.candidate.version, path.join(f.work, 'download'), f.candidate.tgzSHA256, fetcher)).tgzSHA256, f.candidate.tgzSHA256);
- const retryFetcher = (url, options) => String(url).endsWith('/actions/runs/123') ? Response.json({ ...origin, run_attempt: 2, conclusion: 'failure' }) : fetcher(url, options);
+ assert.equal((await verifyDownloaded(path.join(f.work, 'download'), f.candidate.tgzSHA256)).workflow.ref, `refs/heads/${branch}`);
+ const retryFetcher = (url, options) => String(url).endsWith('/actions/runs/123') ? Response.json({ ...producer, run_attempt: 2, conclusion: 'failure' }) : fetcher(url, options);
await assert.rejects(downloadCandidate(f.candidate.version, path.join(f.work, 'retry'), undefined, retryFetcher), /success/);
assert.equal((await downloadCandidate(f.candidate.version, path.join(f.work, 'automatic'), undefined, fetcher)).tgzSHA256, f.candidate.tgzSHA256);
await assert.rejects(downloadCandidate(f.candidate.version, path.join(f.work, 'corrupt'), f.candidate.tgzSHA256, async (url, options) => String(url).includes('signed.') ? new Response('tampered ZIP') : fetcher(url, options)));
+ const other = branch === 'main' ? 'feature/motion' : 'main';
+ await assert.rejects(downloadCandidate(f.candidate.version, path.join(f.work, 'wrong-branch'), f.candidate.tgzSHA256,
+ (url, options) => String(url).endsWith('/actions/runs/123') ? Response.json({ ...producer, head_branch: other }) : fetcher(url, options)));
+});
+
+test('old main receipts remain readable but unregistered candidate branches cannot seal artifacts', async t => {
+ const f = await candidateFixture(t);
+ const { head_branch, ...legacy } = f.provenance;
+ await writeFile(path.join(f.directory, 'provenance.json'), JSON.stringify(legacy));
+ assert.equal((await verifyDownloaded(f.directory, f.candidate.tgzSHA256)).workflow.ref, 'refs/heads/main');
+ await assert.rejects(candidateFixture(t, 'codex/unreviewed'), /only from main or feature/);
});
function registry(candidate, exists = true, tag = candidate.version, latest = '0.5.0') {
@@ -218,12 +265,16 @@ test('daily build and publication are separate manual entries without an indepen
const header = workflow.split('\njobs:\n')[0];
assert(build.includes('workflow_dispatch:') && build.includes('version:') && build.includes('source_sha:'));
assert(build.includes('name: ' + candidateJobName) && build.includes('ref: ${{ steps.source.outputs.source_sha }}'));
+ assert(build.includes("github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/motion'"));
assert(build.includes('--template-env=dev') && !build.includes('--template-env=prod'));
assert(build.includes('HYPERFRAMES_BROWSER_PATH: /usr/bin/google-chrome') && build.includes('\"$HYPERFRAMES_BROWSER_PATH\" --version'));
assert(!/apt-get install[^\n]*\bchromium\b/.test(build), 'Candidate builds must not install Ubuntu desktop snaps');
- assert(build.includes('name: motion-candidate-${{ inputs.version }}') && build.includes('candidate-install.md'));
+ assert.match(build, /version:\n(?:[^\n]*\n)*? required: false\n default: ''/);
+ assert(build.includes('MOTION_VERSION: ${{ steps.source.outputs.version }}'));
+ assert(build.includes('name: motion-candidate-${{ steps.source.outputs.version }}') && build.includes('candidate-install.md'));
assert(!build.includes('concurrency:') && !build.includes('secrets.') && !build.includes('id-token:'));
assert(header.includes('version:') && header.includes('accepted:') && header.includes('default: false'));
+ assert.match(header, /version:\n(?:[^\n]*\n)*? required: true/);
for (const manualField of ['candidate_run_id:', 'source_sha:', 'tgz_sha256:', 'acceptance_sha256:', 'approved:', 'action:']) assert(!header.includes(manualField));
assert(!workflow.includes(' candidate:') && !workflow.includes('environment:'));
assert(header.includes('group: motion-test-publication') && header.includes('cancel-in-progress: false'));