Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: harden CI cancellation contracts (#5519)
[._.]/ Adam Eivy428cdbd36b7b
diff --git a/scripts/cancel-current-ci-run.js b/scripts/cancel-current-ci-run.jsindex 8e2b6e675c..1951cba449 100644--- a/scripts/cancel-current-ci-run.js+++ b/scripts/cancel-current-ci-run.js@@ -26,15 +26,33 @@ function targetFromEnv(env) {? env.GITHUB_RUN_ID.trim(): '';const token = typeof env.GITHUB_TOKEN === 'string' ? env.GITHUB_TOKEN.trim() : '';+ const configuredApiUrl = typeof env.GITHUB_API_URL === 'string'+ ? env.GITHUB_API_URL.trim()+ : '';if (!/^[^/\s]+\/[^/\s]+$/.test(repository) || !/^\d+$/.test(runId) || !token) {return null;}+ let apiBase = GITHUB_API_BASE;+ if (configuredApiUrl) {+ let parsedApiUrl;+ try {+ parsedApiUrl = new URL(configuredApiUrl);+ } catch {+ return null;+ }+ if (parsedApiUrl.protocol !== 'https:' || parsedApiUrl.username || parsedApiUrl.password+ || parsedApiUrl.search || parsedApiUrl.hash) {+ return null;+ }+ apiBase = configuredApiUrl.replace(/\/+$/, '');+ }+const [owner, repo] = repository.split('/');return {token,- url: `${GITHUB_API_BASE}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/actions/runs/${runId}/cancel`,+ url: `${apiBase}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/actions/runs/${runId}/cancel`,};}diff --git a/scripts/cancel-current-ci-run.test.js b/scripts/cancel-current-ci-run.test.jsindex 9bde971941..b317404248 100644--- a/scripts/cancel-current-ci-run.test.js+++ b/scripts/cancel-current-ci-run.test.js@@ -54,6 +54,48 @@ describe('cancelCurrentCiRun', () => {expect(logger.error).not.toHaveBeenCalled();});+ it('uses the Actions API base and falls back to the public API when it is absent', async () => {+ const { fetchImpl, logger } = setup();+ fetchImpl.mockResolvedValue(response(202));++ await cancelCurrentCiRun({+ env: { ...ENV, GITHUB_API_URL: 'https://github.example.test/api/v3/' },+ fetchImpl,+ logger,+ });+ expect(fetchImpl).toHaveBeenLastCalledWith(+ 'https://github.example.test/api/v3/repos/example/portos/actions/runs/123456789/cancel',+ expect.any(Object),+ );++ fetchImpl.mockClear();+ await cancelCurrentCiRun({ env: ENV, fetchImpl, logger });+ expect(fetchImpl).toHaveBeenCalledWith(+ 'https://api.github.com/repos/example/portos/actions/runs/123456789/cancel',+ expect.any(Object),+ );+ });++ it('rejects an unsafe API base without making a request', async () => {+ const { fetchImpl, logger } = setup();++ await expect(cancelCurrentCiRun({+ env: { ...ENV, GITHUB_API_URL: 'http://example.invalid/api/v3' },+ fetchImpl,+ logger,+ })).resolves.toEqual({ outcome: 'skipped', reason: 'invalid-environment' });++ expect(fetchImpl).not.toHaveBeenCalled();++ await expect(cancelCurrentCiRun({+ env: { ...ENV, GITHUB_API_URL: 'not-a-url' },+ fetchImpl,+ logger,+ })).resolves.toEqual({ outcome: 'skipped', reason: 'invalid-environment' });++ expect(fetchImpl).not.toHaveBeenCalled();+ });+it('keeps a permission failure best-effort and preserves the original job failure', async () => {const { fetchImpl, logger } = setup();fetchImpl.mockResolvedValue(response(403));diff --git a/scripts/ci-fail-fast.test.js b/scripts/ci-fail-fast.test.jsindex 490a6cf01a..e297503b28 100644--- a/scripts/ci-fail-fast.test.js+++ b/scripts/ci-fail-fast.test.js@@ -6,8 +6,7 @@ import { describe, expect, it } from 'vitest';const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');const WORKFLOW = readFileSync(join(REPO_ROOT, '.github/workflows/ci.yml'), 'utf8');-const LEAF_JOBS = ['server', 'client', 'database', 'windows-server'];-const NON_LEAF_JOBS = ['impact', 'gate', 'full-gate'];+const NON_LEAF_JOBS = new Set(['impact', 'gate', 'full-gate']);const FAIL_FAST_STEP = [' - name: Cancel sibling CI jobs after failure'," if: failure() && github.event_name == 'pull_request'",@@ -35,9 +34,16 @@ function workflowJobs(yaml) {describe('ci.yml fail-fast cancellation contract', () => {const jobs = workflowJobs(WORKFLOW);+ const leafJobs = Object.keys(jobs).filter((id) => (+ !NON_LEAF_JOBS.has(id) && /^\s*needs:\s*impact\s*$/m.test(jobs[id])+ ));++ it('discovers every direct impact leaf job for contract checks', () => {+ expect(leafJobs).not.toHaveLength(0);+ });it('adds the cancellation step as the final step of every expensive leaf job', () => {- for (const id of LEAF_JOBS) {+ for (const id of leafJobs) {const body = jobs[id];expect(body, id).toBeTruthy();const step = body.slice(body.lastIndexOf(' - name: Cancel sibling CI jobs after failure')).trimEnd();@@ -47,7 +53,7 @@ describe('ci.yml fail-fast cancellation contract', () => {});it('grants only the leaf jobs the minimum cancellation permissions', () => {- for (const id of LEAF_JOBS) {+ for (const id of leafJobs) {const body = jobs[id];expect(body, id).toMatch(/\n permissions:\n contents: read\n actions: write\n/);}@@ -57,7 +63,7 @@ describe('ci.yml fail-fast cancellation contract', () => {});it('does not pass arbitrary repository or run targets to the helper', () => {- for (const id of LEAF_JOBS) {+ for (const id of leafJobs) {const body = jobs[id];expect(body, id).not.toMatch(/GITHUB_(?:REPOSITORY|RUN_ID):/);const step = body.slice(body.lastIndexOf(' - name: Cancel sibling CI jobs after failure'));@@ -67,7 +73,7 @@ describe('ci.yml fail-fast cancellation contract', () => {});it('does not persist the elevated checkout token into leaf job steps', () => {- for (const id of LEAF_JOBS) {+ for (const id of leafJobs) {const body = jobs[id];const checkoutStart = body.indexOf(' - uses: actions/checkout@v7');const nextStep = body.indexOf('\n - ', checkoutStart + 1);