Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

Make release CI risk-based and reuse one tested package

wchao68916f724d31cd4a
diff --git a/.github/actions/setup-browser/action.yml b/.github/actions/setup-browser/action.yml
new file mode 100644
index 0000000..aaf7289
--- /dev/null
+++ b/.github/actions/setup-browser/action.yml
@@ -0,0 +1,30 @@
+name: Pinned isolated Chromium runtime
+description: Install the existing Node/Python/Chromium test environment
+runs:
+ using: composite
+ steps:
+ - uses: actions/setup-node@v6
+ with:
+ node-version: 22
+ cache: npm
+ - uses: actions/setup-python@v6
+ with:
+ python-version: "3.12"
+ - run: npm ci
+ shell: bash
+ - run: python -m pip install playwright==1.58.0
+ shell: bash
+ - if: runner.os == 'Linux'
+ shell: bash
+ run: |
+ # The runner's unrelated Chrome mirror is not needed by Playwright.
+ sudo python - <<'PYTHON'
+ from pathlib import Path
+ for source in Path('/etc/apt/sources.list.d').iterdir():
+ if source.suffix in ('.list', '.sources') and 'dl.google.com/linux/chrome' in source.read_text():
+ source.rename(source.with_suffix(source.suffix + '.disabled'))
+ PYTHON
+ python -m playwright install --with-deps chromium
+ - if: runner.os != 'Linux'
+ run: python -m playwright install chromium
+ shell: bash
diff --git a/.github/workflows/release-safety.yml b/.github/workflows/release-safety.yml
index 2e2c8f8..19fb7db 100644
--- a/.github/workflows/release-safety.yml
+++ b/.github/workflows/release-safety.yml
@@ -2,9 +2,6 @@ name: Release safety
on:
pull_request:
- push:
- branches:
- - main
workflow_dispatch:
permissions:
@@ -14,106 +11,153 @@ concurrency:
group: release-safety-${{ github.ref }}
cancel-in-progress: true
+# Four independent runners divide the existing suite without sharing profiles,
+# ports or media memory. This is processing concurrency, not a product quota.
+env:
+ CI_BROWSER_SHARDS: 4
+ PYTHONUTF8: "1"
+
+defaults:
+ run:
+ shell: bash
+
jobs:
+ plan:
+ name: Plan checks from the actual change
+ runs-on: ubuntu-latest
+ outputs:
+ plan: ${{ steps.plan.outputs.plan }}
+ tier: ${{ steps.plan.outputs.tier }}
+ matrix: ${{ steps.plan.outputs.matrix }}
+ package: ${{ steps.plan.outputs.package }}
+ browser: ${{ steps.plan.outputs.browser }}
+ upgrade: ${{ steps.plan.outputs.upgrade }}
+ connector: ${{ steps.plan.outputs.connector }}
+ steps:
+ - uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
+ - id: plan
+ env:
+ CI_BASE: ${{ github.event.pull_request.base.sha }}
+ run: |
+ if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then
+ python3 tools/ci-release.py plan --full --shards "$CI_BROWSER_SHARDS"
+ else
+ python3 tools/ci-release.py plan --base "$CI_BASE" --shards "$CI_BROWSER_SHARDS"
+ fi
+
source-contracts:
name: Source and compatibility contracts
+ needs: plan
runs-on: ubuntu-latest
steps:
- - name: Check out complete release history
- uses: actions/checkout@v6
+ - uses: actions/checkout@v6
with:
fetch-depth: 0
- - name: Use Node.js
- uses: actions/setup-node@v6
+ - uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- - run: npm ci
- - run: npm ci --prefix connector --ignore-scripts
- - run: npm run verify:source
+ - run: python3 -m unittest discover -s test -p 'ci_release_test.py'
+ - if: needs.plan.outputs.tier == 'light'
+ run: node tools/validate-public-source.mjs
+ - if: needs.plan.outputs.tier != 'light'
+ run: npm ci
+ - if: needs.plan.outputs.tier != 'light'
+ run: npm ci --prefix connector --ignore-scripts
+ - if: needs.plan.outputs.tier != 'light'
+ run: npm run verify:source
- browser-package:
- name: Chromium journeys and packaged upgrade
- needs: source-contracts
+ package:
+ name: Build one package bundle
+ needs: [plan, source-contracts]
+ if: needs.plan.outputs.package == 'true'
runs-on: ubuntu-latest
steps:
- - name: Check out complete release history
- uses: actions/checkout@v6
- with:
- fetch-depth: 0
- - name: Use Node.js
- uses: actions/setup-node@v6
+ - uses: actions/checkout@v6
+ - uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- - name: Use Python
- uses: actions/setup-python@v6
- with:
- python-version: "3.12"
- run: npm ci
- - name: Install the pinned Chromium test runtime
- run: |
- python -m pip install playwright==1.58.0
- # Playwright supplies Chromium; the runner's unrelated Chrome APT mirror
- # can publish inconsistent indexes and is not needed for OS dependencies.
- sudo python - <<'PYTHON'
- from pathlib import Path
- for source in Path('/etc/apt/sources.list.d').iterdir():
- if source.suffix in ('.list', '.sources') and 'dl.google.com/linux/chrome' in source.read_text():
- source.rename(source.with_suffix(source.suffix + '.disabled'))
- PYTHON
- python -m playwright install --with-deps chromium
- - run: npm run test:local-extension
+ - run: npm run package
- run: npm run package:release
- run: node tools/prepare-public-release.mjs
- run: npm run package:connector
- - run: npm run test:upgrade
- - name: Verify extension and connector archives
- run: |
- PROMPTDIRECTOR_PACKAGE_VERSION="$(node -p 'require("./package.json").version')"
- unzip -t "dist/PromptDirector-${PROMPTDIRECTOR_PACKAGE_VERSION}.zip"
- unzip -t "dist/store/PromptDirector-${PROMPTDIRECTOR_PACKAGE_VERSION}-Chrome-Web-Store.zip"
- unzip -t "dist/PromptDirector-${PROMPTDIRECTOR_PACKAGE_VERSION}-Agent-Connector.zip"
- - name: Preserve the exact tested packages
+ - run: python3 tools/ci-release.py seal
+ - uses: actions/upload-artifact@v7
+ with:
+ name: promptdirector-packages-${{ github.sha }}
+ path: dist/**
+ if-no-files-found: error
+ retention-days: 14
+
+ browser-shards:
+ name: Packaged Chromium shard ${{ matrix.shard }}
+ needs: [plan, package]
+ if: needs.plan.outputs.browser == 'true'
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ max-parallel: 4
+ matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}
+ env:
+ CI_PLAN: ${{ needs.plan.outputs.plan }}
+ steps:
+ - uses: actions/checkout@v6
+ - uses: ./.github/actions/setup-browser
+ - uses: actions/download-artifact@v8
+ with:
+ name: promptdirector-packages-${{ github.sha }}
+ path: dist
+ - run: python3 tools/ci-release.py browser --shard "${{ matrix.shard }}" --evidence "dist/ci-browser/${{ matrix.shard }}"
+ - if: always()
uses: actions/upload-artifact@v7
with:
- name: promptdirector-tested-packages-${{ github.sha }}
- path: |
- dist/PromptDirector-*.zip
- dist/store/*.zip
- dist/github/**
+ name: promptdirector-browser-evidence-${{ github.sha }}-${{ matrix.shard }}
+ path: dist/ci-browser/${{ matrix.shard }}/
if-no-files-found: error
retention-days: 14
+ linux-upgrade:
+ name: Linux packaged upgrade
+ needs: [plan, package]
+ if: needs.plan.outputs.upgrade == 'true'
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
+ - uses: ./.github/actions/setup-browser
+ - uses: actions/download-artifact@v8
+ with:
+ name: promptdirector-packages-${{ github.sha }}
+ path: dist
+ - run: python3 tools/ci-release.py verify
+ - run: npm run test:upgrade
+ - run: python3 tools/ci-release.py verify
+
windows-portability:
name: Windows packaged data and project interactions
- needs: source-contracts
+ needs: [plan, package]
+ if: needs.plan.outputs.upgrade == 'true'
runs-on: windows-latest
- env:
- PYTHONUTF8: "1"
- defaults:
- run:
- shell: bash
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- - uses: actions/setup-node@v6
+ - uses: ./.github/actions/setup-browser
+ - uses: actions/download-artifact@v8
with:
- node-version: 22
- cache: npm
- - uses: actions/setup-python@v6
- with:
- python-version: "3.12"
- - run: npm ci
- - run: python -m pip install playwright==1.58.0
- - run: python -m playwright install chromium
+ name: promptdirector-packages-${{ github.sha }}
+ path: dist
+ - run: python tools/ci-release.py verify
- name: Guard import deduplication growth and replacement semantics
run: node --test test/library-import-dedup.test.js
- - run: npm run package
- - name: Check the Windows installation package
+ - name: Check the same installation package on Windows
run: |
- python - <<'PY'
+ python - <<'PYTHON'
import json, os, pathlib, subprocess, sys, zipfile
version = json.loads(pathlib.Path('extension/manifest.json').read_text())['version']
destination = pathlib.Path(os.environ['RUNNER_TEMP']) / 'PromptDirector'
@@ -122,11 +166,14 @@ jobs:
env = {**os.environ, 'PROMPTDIRECTOR_E2E_EXTENSION_DIR': str(destination), 'PROMPTDIRECTOR_E2E_BLOCK_EXTERNAL_NETWORK': '1'}
for script in ['project_tree_e2e.py', 'library_import_resources_e2e.py', 'library_import_ui_e2e.py', 'library_import_preview_e2e.py', 'library_import_interruption_e2e.py', 'image_generation_info_e2e.py', 'skill_cover_e2e.py']:
subprocess.run([sys.executable, f'test/{script}'], env=env, check=True)
- PY
+ PYTHON
- run: npm run test:upgrade
+ - run: python tools/ci-release.py verify
connector-platforms:
name: Native connector (${{ matrix.os }})
+ needs: [plan, source-contracts]
+ if: needs.plan.outputs.connector == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@@ -137,6 +184,43 @@ jobs:
- uses: actions/setup-node@v6
with:
node-version: 22
+ cache: npm
+ cache-dependency-path: connector/package-lock.json
- run: npm ci --prefix connector --ignore-scripts
- run: node --test connector/test/*.test.mjs
- shell: bash
+
+ browser-package:
+ # Keep the existing required check; an always-run gate rejects failures,
+ # cancellations, missing shards and packages with a different source/digest.
+ name: Chromium journeys and packaged upgrade
+ needs: [plan, source-contracts, package, browser-shards, linux-upgrade, windows-portability, connector-platforms]
+ if: always()
+ runs-on: ubuntu-latest
+ env:
+ CI_PLAN: ${{ needs.plan.outputs.plan }}
+ CI_NEEDS: ${{ toJSON(needs) }}
+ steps:
+ - uses: actions/checkout@v6
+ - if: needs.package.result == 'success'
+ uses: actions/download-artifact@v8
+ with:
+ name: promptdirector-packages-${{ github.sha }}
+ path: dist
+ - if: needs.browser-shards.result == 'success'
+ uses: actions/download-artifact@v8
+ with:
+ pattern: promptdirector-browser-evidence-${{ github.sha }}-*
+ path: dist/ci-browser
+ - run: python3 tools/ci-release.py gate
+ - if: needs.plan.outputs.tier == 'full'
+ uses: actions/upload-artifact@v7
+ with:
+ name: promptdirector-tested-packages-${{ github.sha }}
+ path: |
+ dist/PromptDirector-*.zip
+ dist/store/*.zip
+ dist/github/**
+ dist/ci-package.json
+ dist/ci-validation.json
+ if-no-files-found: error
+ retention-days: 14
diff --git a/docs/RELEASE_VERIFICATION.md b/docs/RELEASE_VERIFICATION.md
new file mode 100644
index 0000000..3ea8356
--- /dev/null
+++ b/docs/RELEASE_VERIFICATION.md
@@ -0,0 +1,32 @@
+# Release verification
+
+CI classifies the actual PR diff, keeps the two existing required checks, and fails the final gate when planned work fails, is cancelled, is missing, or tests different package bytes.
+
+| Change | CI coverage |
+|---|---|
+| Public Markdown/license documentation | Public boundary check and CI policy tests; no browser or upgrade jobs |
+| Known page-local HTML/CSS | Full source contracts plus the affected page and shared UI browser scenarios |
+| Registered browser test only | Full source contracts plus that scenario |
+| Source unit tests only | Full source contracts |
+| Connector code only | Full source contracts, one package build and connector tests on Linux/macOS/Windows |
+| Shared runtime, storage/media/capture logic, dependencies, versions, fixtures/helpers, CI/build tools or unknown files | Full source contracts, every registered browser scenario, both installed-profile upgrades and all connector platforms |
+
+The conservative default is full coverage. A manual run of `Release safety` also always uses full coverage; it cannot force a reduced gate. No workflow-wide path filters leave required checks pending.
+
+## One package, independent tests
+
+The package job builds the fixed-ID public extension, store package and connector archive once. It checks ZIP integrity/channel identity and records each SHA-256 plus the Git source tree in `ci-package.json`. Four independent browser runners partition the authoritative `test/run_e2e.py` registry; each uses isolated profiles and the same downloaded package. Linux and Windows upgrade jobs use that same bundle in parallel. Four is configured in the workflow to reduce sequential waiting without running several large-media browsers in the same runner.
+
+Each browser receipt includes its complete planned scenario list, every result, preflight identity and package metadata. The required `Chromium journeys and packaged upgrade` gate verifies that all shards are present exactly once and all selected scenarios passed. Full coverage retains the 344 MB X save/readback, recovery and actual worker-tool regressions. Source, upgrade and connector job failures also block the gate.
+
+Only a full successful run uploads `promptdirector-tested-packages-<commit>` with `ci-validation.json`; partial checks never produce a full-release artifact. Download that exact artifact for publication and compare its recorded source tree with the merged commit. Publish the existing ZIP/checksum files after readback verification; do not rebuild them. The store ZIP remains a separate channel.
+
+## Triggers and local checks
+
+Protected PRs run the gate. Merging the same source does not start a second identical main-branch run; explicit full verification remains available through `workflow_dispatch`. The existing branch-protection check names are unchanged. Keep branch protection enabled for main.
+
+Local development still supports `npm run test:local-extension` for a complete packaged lab and `python3 test/run_e2e.py --script <registered-script>` for focused checks. CI's `--scripts` and JSON receipts use the same registry and runner, including failed results. Fix and run affected checks before another commit; unchanged full evidence need not be repeated locally.
+
+Policy regression checks: `python3 -m unittest discover -s test -p ci_release_test.py`. The full Node source suite also executes them. Scope examples and failure cases cover omitted/duplicate shards, replaced package digests/source trees, failed/cancelled/skipped required jobs, and partial evidence mislabeled as full.
+
+The policy does not replace acceptance of live sites, paid providers, a user's daily installation or Store submission.
diff --git a/test/ci_release_test.py b/test/ci_release_test.py
new file mode 100644
index 0000000..0419c78
--- /dev/null
+++ b/test/ci_release_test.py
@@ -0,0 +1,128 @@
+"""Release planning must never turn partial, missing or changed evidence green."""
+import copy
+import importlib.util
+import sys
+import unittest
+from pathlib import Path
+
+spec = importlib.util.spec_from_file_location('ci_release', Path(__file__).parents[1] / 'tools/ci-release.py')
+ci = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(ci)
+
+
+class ReleasePlanning(unittest.TestCase):
+ def test_docs_do_not_start_browsers_upgrades_or_connector_installations(self):
+ plan = ci.make_plan(['README.md', 'docs/DATA_COMPATIBILITY.md', 'connector/INSTALL.md'])
+ self.assertEqual(plan['tier'], 'light')
+ self.assertFalse(any(plan[key] for key in ['package', 'browser', 'upgrade', 'connector']))
+
+ def test_known_page_styles_run_related_pages_and_shared_ui(self):
+ plan = ci.make_plan(['extension/composer-page.css'])
+ self.assertEqual(plan['tier'], 'targeted')
+ self.assertIn('composer_video_dialogue_e2e.py', plan['scripts'])
+ self.assertIn('composer_library_host_e2e.py', plan['scripts'])
+ self.assertIn('ui_foundation_e2e.py', plan['scripts'])
+ self.assertNotIn('x_large_media_save_e2e.py', plan['scripts'])
+ self.assertFalse(plan['upgrade'])
+
+ def test_shared_data_media_dependencies_versions_and_unknown_paths_run_every_scenario(self):
+ for path in ['extension/background.js', 'extension/page-session-media.js', 'extension/zip.js',
+ 'extension/library-storage.js', 'extension/manifest.json', 'package-lock.json',
+ 'test/e2e_support.py', '.github/workflows/release-safety.yml',
+ 'extension/new-feature.js', 'new-configuration.json']:
+ with self.subTest(path=path):
+ plan = ci.make_plan([path])
+ self.assertEqual(plan['tier'], 'full')
+ self.assertEqual(plan['scripts'], ci.SCRIPTS)
+ self.assertIn('x_large_media_save_e2e.py', plan['scripts'])
+ self.assertTrue(plan['upgrade'] and plan['connector'])
+
+ def test_registered_browser_test_is_targeted_but_helpers_are_full(self):
+ plan = ci.make_plan(['test/x_large_media_save_e2e.py'])
+ self.assertEqual(plan['scripts'], ['x_large_media_save_e2e.py'])
+ self.assertEqual(plan['shards'], 1)
+ self.assertEqual(ci.make_plan(['test/fixtures/changed.mp4'])['tier'], 'full')
+
+ def test_connector_only_changes_check_all_connector_platforms_without_full_browser_suite(self):
+ plan = ci.make_plan(['connector/mcp.mjs'])
+ self.assertEqual(plan['tier'], 'targeted')
+ self.assertTrue(plan['connector'] and plan['package'])
+ self.assertFalse(plan['browser'] or plan['upgrade'])
+
+ def test_mixed_change_cannot_be_downgraded_by_docs_or_a_style_change(self):
+ self.assertEqual(ci.make_plan(['README.md', 'extension/library.css', 'extension/media-store.js'])['tier'], 'full')
+ self.assertEqual(ci.make_plan([], force_full=True)['scripts'], ci.SCRIPTS)
+
+ def test_shards_partition_every_registered_scenario_exactly_once(self):
+ plan = ci.make_plan([], force_full=True, shards=4)
+ chunks = [plan['scripts'][i::plan['shards']] for i in range(plan['shards'])]
+ self.assertEqual(sorted(sum(chunks, [])), sorted(ci.SCRIPTS))
+ self.assertEqual(len(sum(chunks, [])), len(set(sum(chunks, []))))
+
+
+class EvidenceGate(unittest.TestCase):
+ def setUp(self):
+ self.plan = ci.make_plan([], force_full=True, shards=4)
+ self.package = {'tree': 'current-tree', 'version': '1.25.0', 'extensionId': 'fixed-id',
+ 'archives': {'extension.zip': 'complete-sha'}}
+ self.reports = []
+ for index in range(self.plan['shards']):
+ scripts = self.plan['scripts'][index::self.plan['shards']]
+ url = 'chrome-extension://fixed-id/'
+ self.reports.append({'shard': index, 'scripts': scripts, 'package': self.package,
+ 'status': 'passed', 'results': [{'script': s, 'returncode': 0} for s in scripts],
+ 'preflight': {'extensionId': 'fixed-id', 'manifestVersion': '1.25.0',
+ 'serviceWorker': url + 'background.js', 'pageErrors': [],
+ 'pages': [url + n for n in ['collector.html', 'library.html', 'composer.html']]}})
+ self.jobs = {name: {'result': 'success'} for name in ['plan', 'source-contracts', 'package',
+ 'browser-shards', 'linux-upgrade', 'windows-portability', 'connector-platforms']}
+
+ def test_complete_same_package_evidence_passes(self):
+ ci.validate_jobs(self.plan, self.jobs)
+ ci.validate_reports(self.plan, self.package, self.reports)
+
+ def test_missing_duplicate_or_failed_shards_block_release(self):
+ for mutate in [lambda r: r.pop(), lambda r: r.__setitem__(1, r[0]),
+ lambda r: r[0].update(status='failed'),
+ lambda r: r[0]['results'][0].update(returncode=1),
+ lambda r: r[0]['results'].pop()]:
+ reports = copy.deepcopy(self.reports)
+ mutate(reports)
+ with self.assertRaises(ValueError):
+ ci.validate_reports(self.plan, self.package, reports)
+
+ def test_replaced_package_source_or_preflight_identity_blocks_release(self):
+ for mutate in [lambda r: r[0]['package'].update(tree='other-source'),
+ lambda r: r[0]['package']['archives'].update({'extension.zip': 'other-bytes'}),
+ lambda r: r[0]['preflight'].update(extensionId='other-id'),
+ lambda r: r[0]['preflight'].update(pageErrors=['runtime exception'])]:
+ reports = copy.deepcopy(self.reports)
+ mutate(reports)
+ with self.assertRaises(ValueError):
+ ci.validate_reports(self.plan, self.package, reports)
+
+ def test_failure_cancellation_and_skipped_required_jobs_block_release(self):
+ for name in self.jobs:
+ for state in ['failure', 'cancelled', 'skipped']:
+ jobs = copy.deepcopy(self.jobs)
+ jobs[name]['result'] = state
+ with self.assertRaises(ValueError):
+ ci.validate_jobs(self.plan, jobs)
+
+ def test_documentation_gate_requires_real_plan_and_source_success(self):
+ plan = ci.make_plan(['README.md'])
+ jobs = {name: {'result': 'success' if name in ['plan', 'source-contracts'] else 'skipped'} for name in self.jobs}
+ ci.validate_jobs(plan, jobs)
+ jobs['source-contracts']['result'] = 'failure'
+ with self.assertRaises(ValueError):
+ ci.validate_jobs(plan, jobs)
+
+ def test_partial_evidence_cannot_be_called_a_full_release(self):
+ plan = copy.deepcopy(self.plan)
+ plan['scripts'] = plan['scripts'][:-1]
+ with self.assertRaises(ValueError):
+ ci.validate_jobs(plan, self.jobs)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/test/release-gate.test.js b/test/release-gate.test.js
index 53f6d1f..07b28cd 100644
--- a/test/release-gate.test.js
+++ b/test/release-gate.test.js
@@ -41,14 +41,22 @@ test("release verification rehearses an installed-profile upgrade with the final
test("GitHub runs source contracts and packaged Chromium journeys before main can advance", async () => {
const workflow = await readFile(new URL("../.github/workflows/release-safety.yml", import.meta.url), "utf8");
assert.match(workflow, /pull_request:/);
- assert.match(workflow, /push:[\s\S]*branches:[\s\S]*main/);
+ assert.doesNotMatch(workflow, /^ push:/m, 'protected PR evidence is not rerun unchanged after merge');
+ assert.match(workflow, /workflow_dispatch:/, 'a full release can be explicitly verified');
assert.match(workflow, /fetch-depth:\s*0/);
assert.match(workflow, /npm run verify:source/);
- assert.match(workflow, /npm run test:local-extension/);
+ assert.match(workflow, /ci-release\.py browser/, 'shards load the single packaged runtime');
assert.match(workflow, /npm run package:release/);
assert.match(workflow, /npm run package/);
assert.match(workflow, /npm run test:upgrade/);
- assert.match(workflow, /PROMPTDIRECTOR_PACKAGE_VERSION="\$\(node -p 'require\("\.\/package\.json"\)\.version'\)"/);
- assert.match(workflow, /unzip -t "dist\/PromptDirector-\$\{PROMPTDIRECTOR_PACKAGE_VERSION\}\.zip"/);
- assert.match(workflow, /unzip -t "dist\/store\/PromptDirector-\$\{PROMPTDIRECTOR_PACKAGE_VERSION\}-Chrome-Web-Store\.zip"/);
+ assert.match(workflow, /ci-release\.py seal/, 'all ZIP channels have checksums and CRC verified before sharing');
+ assert.match(workflow, /ci-release\.py gate/);
+ assert.match(workflow, /if: always\(\)/);
+});
+
+test('CI planning and package evidence reject unsafe reductions and missing results', async () => {
+ const { execFileSync } = await import('node:child_process');
+ execFileSync(process.platform === 'win32' ? 'python' : 'python3',
+ ['-m', 'unittest', 'discover', '-s', 'test', '-p', 'ci_release_test.py'],
+ { cwd: new URL('..', import.meta.url), stdio: 'pipe' });
});
diff --git a/test/run_e2e.py b/test/run_e2e.py
index b47d3f9..7a938e4 100644
--- a/test/run_e2e.py
+++ b/test/run_e2e.py
@@ -1,10 +1,11 @@
from __future__ import annotations
import argparse
+import json
import subprocess
import sys
import time
-from dataclasses import dataclass
+from dataclasses import asdict, dataclass
from pathlib import Path
@@ -196,12 +197,17 @@ def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run PromptDirector browser regression scripts")
parser.add_argument("--group", choices=["all", "case-management"], default="all")
parser.add_argument("--script", choices=SCRIPTS, help="Run one registered browser regression script")
- return parser.parse_args()
+ parser.add_argument("--scripts", nargs='+', choices=SCRIPTS, help="Run the planned CI scenarios")
+ parser.add_argument("--report", type=Path, help="Save every scenario result, including failures")
+ args = parser.parse_args()
+ if args.scripts and (args.script or args.group != 'all' or len(args.scripts) != len(set(args.scripts))):
+ parser.error('Explicit CI scenarios must be unique and cannot be combined with a group or single script')
+ return args
def main() -> None:
args = parse_args()
- scripts = [args.script] if args.script else CASE_MANAGEMENT_SCRIPTS if args.group == "case-management" else SCRIPTS
+ scripts = args.scripts or ([args.script] if args.script else CASE_MANAGEMENT_SCRIPTS if args.group == "case-management" else SCRIPTS)
results: list[Result] = []
for script in scripts:
started = time.monotonic()
@@ -224,6 +230,9 @@ def main() -> None:
state = "通过" if result.returncode == 0 else "失败"
print(f"- {state} {result.script}: {result.duration:.1f}s")
failed = [result for result in results if result.returncode]
+ if args.report:
+ args.report.parent.mkdir(parents=True, exist_ok=True)
+ args.report.write_text(json.dumps([asdict(result) for result in results], ensure_ascii=False, indent=2), encoding='utf-8')
if failed:
raise SystemExit(1)
diff --git a/tools/ci-release.py b/tools/ci-release.py
new file mode 100644
index 0000000..60095f0
--- /dev/null
+++ b/tools/ci-release.py
@@ -0,0 +1,254 @@
+"""Risk-based CI planning and verification of one immutable packaged runtime."""
+import argparse
+import base64
+import hashlib
+import json
+import os
+import subprocess
+import sys
+import tempfile
+import zipfile
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT / 'test'))
+from run_e2e import SCRIPTS
+
+# Only established page-local presentation files qualify for targeted browser
+# coverage. Shared logic, storage, media, dependencies and unknown paths are full.
+PAGE_SCOPES = {
+ 'library': ('library', 'detail', 'video_detail', 'project', 'sharing', 'undo',
+ 'case_', 'manager', 'material_management', 'settings', 'selection_video'),
+ 'composer': ('composer', 'compatible_composer', 'creative', 'ai_', 'zhipu'),
+ 'skills': ('skill', 'creative_skill', 'curated_skill'),
+ 'curated': ('curated',),
+}
+PAGE_FILES = {
+ 'extension/library.html': 'library', 'extension/library.css': 'library',
+ 'extension/library-layout.css': 'library',
+ 'extension/composer.html': 'composer', 'extension/composer-page.css': 'composer',
+ 'extension/skills.html': 'skills', 'extension/skills-page.css': 'skills',
+ 'extension/curated.html': 'curated', 'extension/curated.css': 'curated',
+}
+SHARED_UI_SCRIPTS = {'frontend_compact_surfaces_e2e.py', 'ui_foundation_e2e.py',
+ 'ui_regressions_e2e.py', 'brand_i18n_e2e.py', 'english_interaction_states_e2e.py'}
+
+
+def make_plan(paths, force_full=False, shards=4):
+ if not isinstance(shards, int) or shards < 1:
+ raise ValueError('Browser shard count must be a positive integer')
+ if len(SCRIPTS) != len(set(SCRIPTS)):
+ raise ValueError('Browser registry contains duplicate scripts')
+ selected, scopes = set(), set()
+ full, connector = force_full, False
+ for path in paths:
+ file = Path(path)
+ if file.suffix == '.md' and (file.parent == Path('.') or
+ path.startswith(('docs/', 'store/', 'connector/'))):
+ continue
+ if path in {'LICENSE', 'NOTICE'}:
+ continue
+ if path.startswith('connector/'):
+ scopes.add('connector')
+ connector = True
+ elif path in PAGE_FILES:
+ area = PAGE_FILES[path]
+ scopes.add(area)
+ selected.update(script for script in SCRIPTS
+ if script.startswith(PAGE_SCOPES[area]) or script in SHARED_UI_SCRIPTS)
+ elif path.startswith('test/') and file.name.endswith('.test.js'):
+ scopes.add('source-tests')
+ elif path == f'test/{file.name}' and file.name in SCRIPTS:
+ scopes.add('browser-tests')
+ selected.add(file.name)
+ else:
+ full = True
+ tier = 'full' if full else 'targeted' if scopes else 'light'
+ scripts = list(SCRIPTS) if full else [script for script in SCRIPTS if script in selected]
+ count = min(shards, len(scripts)) if scripts else 0
+ return {'tier': tier, 'changedFiles': sorted(set(paths)), 'scripts': scripts,
+ 'shards': count, 'matrix': {'include': [{'shard': index} for index in range(count)]},
+ 'package': bool(scripts) or connector or full, 'browser': bool(scripts),
+ 'upgrade': full, 'connector': connector or full, 'forceFull': force_full}
+
+
+def git(*args):
+ return subprocess.check_output(['git', *args], cwd=ROOT).decode().strip()
+
+
+def write_json(path, value):
+ Path(path).parent.mkdir(parents=True, exist_ok=True)
+ Path(path).write_text(json.dumps(value, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+
+
+def digest(path):
+ with Path(path).open('rb') as file:
+ return hashlib.file_digest(file, 'sha256').hexdigest()
+
+
+def archives():
+ version = json.loads((ROOT / 'extension/manifest.json').read_text())['version']
+ return [f'PromptDirector-{version}.zip', f'store/PromptDirector-{version}-Chrome-Web-Store.zip',
+ f'PromptDirector-{version}-Agent-Connector.zip']
+
+
+def checked_zip(path):
+ archive = zipfile.ZipFile(path)
+ names = archive.namelist()
+ if len(names) != len(set(names)) or any(name.startswith('/') or name[1:2] == ':' or '\\' in name or
+ '..' in Path(name).parts for name in names) or archive.testzip() is not None:
+ archive.close()
+ raise ValueError('Invalid archive paths, duplicate files or corrupt ZIP')
+ return archive
+
+
+def bundle_metadata(directory):
+ directory = Path(directory)
+ manifest = json.loads((ROOT / 'extension/manifest.json').read_text())
+ names = archives()
+ for index, name in enumerate(names):
+ with checked_zip(directory / name) as archive:
+ if index < 2:
+ packaged = json.loads(archive.read('manifest.json'))
+ expected = manifest if index == 0 else {k: v for k, v in manifest.items() if k != 'key'}
+ if packaged != expected:
+ raise ValueError('Packaged manifest differs from the checked-out source/channel')
+ if ('local-extension-upgrade.js' in archive.namelist()) != (index == 0):
+ raise ValueError('Incorrect upgrade capability for package channel')
+ else:
+ if any('node_modules' in Path(name).parts or archive.read(name) != (ROOT / name).read_bytes()
+ for name in archive.namelist()):
+ raise ValueError('Connector archive differs from source or includes installed dependencies')
+ public = directory / 'github' / manifest['version']
+ if digest(public / names[0]) != digest(directory / names[0]):
+ raise ValueError('Public release copy differs from the tested fixed-ID package')
+ if (public / 'SHA256SUMS').read_text().split() != [digest(directory / names[0]), names[0]]:
+ raise ValueError('Public release checksum does not match')
+ key_hash = hashlib.sha256(base64.b64decode(manifest['key'])).hexdigest()[:32]
+ extension_id = ''.join(chr(ord('a') + int(char, 16)) for char in key_hash)
+ return {'tree': git('rev-parse', 'HEAD^{tree}'), 'version': manifest['version'],
+ 'extensionId': extension_id, 'archives': {name: digest(directory / name) for name in names}}
+
+
+def verify_bundle(directory):
+ actual = bundle_metadata(directory)
+ expected = json.loads((Path(directory) / 'ci-package.json').read_text())
+ if actual != expected:
+ raise ValueError('Package bytes or source tree changed after build')
+ return actual
+
+
+def validate_reports(plan, metadata, reports):
+ if len(reports) != plan['shards']:
+ raise ValueError('Missing browser shard receipt')
+ indexes = [report['shard'] for report in reports]
+ if sorted(indexes) != list(range(plan['shards'])):
+ raise ValueError('Duplicate or unexpected browser shard')
+ completed = []
+ for report in reports:
+ expected = plan['scripts'][report['shard']::plan['shards']]
+ if report['package'] != metadata or report['scripts'] != expected:
+ raise ValueError('Shard tested a different package or script selection')
+ if report['status'] != 'passed' or [r['script'] for r in report['results']] != expected:
+ raise ValueError('Shard failed or omitted a planned scenario')
+ if any(result['returncode'] != 0 for result in report['results']):
+ raise ValueError('Browser scenario failed')
+ facts = report['preflight']
+ extension_url = f"chrome-extension://{metadata['extensionId']}/"
+ if (facts['extensionId'] != metadata['extensionId'] or facts['manifestVersion'] != metadata['version']
+ or facts['serviceWorker'] != extension_url + 'background.js'
+ or facts['pages'] != [extension_url + name for name in ['collector.html', 'library.html', 'composer.html']]
+ or facts['pageErrors']):
+ raise ValueError('Packaged browser preflight identity/pages/errors mismatch')
+ completed.extend(expected)
+ if sorted(completed) != sorted(plan['scripts']) or len(completed) != len(set(completed)):
+ raise ValueError('Browser coverage is incomplete or duplicated')
+
+
+def validate_jobs(plan, jobs):
+ if plan['tier'] == 'full' and plan['scripts'] != SCRIPTS:
+ raise ValueError('Full release evidence requires the complete browser registry')
+ expected = {'plan': True, 'source-contracts': True, 'package': plan['package'],
+ 'browser-shards': plan['browser'], 'linux-upgrade': plan['upgrade'],
+ 'windows-portability': plan['upgrade'], 'connector-platforms': plan['connector']}
+ for name, required in expected.items():
+ result = jobs.get(name, {}).get('result')
+ if result != ('success' if required else 'skipped'):
+ raise ValueError(f'{name}: expected {"success" if required else "skipped"}, got {result}')
+
+
+def run_browser(plan, shard, directory, evidence):
+ metadata = verify_bundle(directory)
+ if not 0 <= shard < plan['shards']:
+ raise ValueError('Unexpected browser shard index')
+ scripts = plan['scripts'][shard::plan['shards']]
+ evidence = Path(evidence).resolve()
+ evidence.mkdir(parents=True, exist_ok=True)
+ with tempfile.TemporaryDirectory(prefix='pd-ci-package-') as temporary:
+ with checked_zip(Path(directory) / archives()[0]) as archive:
+ archive.extractall(temporary)
+ env = {**os.environ, 'PROMPTDIRECTOR_E2E_EXTENSION_DIR': temporary,
+ 'PROMPTDIRECTOR_LAB_EVIDENCE_DIR': str(evidence),
+ 'PROMPTDIRECTOR_E2E_EXPECTED_EXTENSION_ID': metadata['extensionId'],
+ 'PROMPTDIRECTOR_E2E_EXPECTED_VERSION': metadata['version'],
+ 'PROMPTDIRECTOR_E2E_BLOCK_EXTERNAL_NETWORK': '1'}
+ subprocess.run([sys.executable, 'test/local_extension_lab_e2e.py'], cwd=ROOT, env=env, check=True)
+ result_file = evidence / 'results.json'
+ run = subprocess.run([sys.executable, 'test/run_e2e.py', '--scripts', *scripts,
+ '--report', str(result_file)], cwd=ROOT, env=env)
+ report = {'shard': shard, 'scripts': scripts, 'package': metadata,
+ 'status': 'passed' if run.returncode == 0 else 'failed',
+ 'preflight': json.loads((evidence / 'preflight.json').read_text()),
+ 'results': json.loads(result_file.read_text())}
+ write_json(evidence / f'shard-{shard}.json', report)
+ if run.returncode:
+ raise ValueError('Browser shard failed; receipt retained')
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('action', choices=['plan', 'seal', 'verify', 'browser', 'gate'])
+ parser.add_argument('--base')
+ parser.add_argument('--full', action='store_true')
+ parser.add_argument('--shards', type=int, default=4)
+ parser.add_argument('--shard', type=int)
+ parser.add_argument('--directory', default='dist')
+ parser.add_argument('--evidence', default='dist/ci-browser')
+ args = parser.parse_args()
+ if args.action == 'plan':
+ if not args.base and not args.full:
+ parser.error('A real comparison base or explicit full validation is required')
+ paths = subprocess.check_output(['git', 'diff', '--name-only', '--no-renames', '-z',
+ args.base, 'HEAD'], cwd=ROOT).decode().split('\0')[:-1] if args.base else []
+ plan = make_plan(paths, args.full, args.shards)
+ output = {'plan': json.dumps(plan, separators=(',', ':')), 'tier': plan['tier'],
+ 'matrix': json.dumps(plan['matrix'], separators=(',', ':')),
+ **{key: str(plan[key]).lower() for key in ['package', 'browser', 'upgrade', 'connector']}}
+ if os.environ.get('GITHUB_OUTPUT'):
+ with open(os.environ['GITHUB_OUTPUT'], 'a') as file:
+ for key, value in output.items():
+ file.write(f'{key}={value}\n')
+ print(json.dumps(plan, indent=2))
+ elif args.action == 'seal':
+ write_json(Path(args.directory) / 'ci-package.json', bundle_metadata(args.directory))
+ elif args.action == 'verify':
+ print(json.dumps(verify_bundle(args.directory), indent=2))
+ else:
+ plan = json.loads(os.environ['CI_PLAN'])
+ if args.action == 'browser':
+ run_browser(plan, args.shard, args.directory, args.evidence)
+ else:
+ validate_jobs(plan, json.loads(os.environ['CI_NEEDS']))
+ metadata = verify_bundle(args.directory) if plan['package'] else None
+ if plan['browser']:
+ reports = [json.loads(path.read_text()) for path in Path(args.evidence).rglob('shard-*.json')]
+ validate_reports(plan, metadata, reports)
+ receipt = {'tier': plan['tier'], 'status': 'passed', 'package': metadata,
+ 'scripts': plan['scripts'], 'fullReleaseEvidence': plan['tier'] == 'full',
+ 'runId': os.environ.get('GITHUB_RUN_ID'), 'sourceTree': git('rev-parse', 'HEAD^{tree}')}
+ write_json(Path(args.directory) / 'ci-validation.json', receipt)
+ print(json.dumps(receipt, indent=2))
+
+
+if __name__ == '__main__':
+ main()