Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

ci: publish benchmark reports when evidence arrives

ldm054a9b5636143
diff --git a/.github/scripts/wait-for-workflow-artifact.cjs b/.github/scripts/wait-for-workflow-artifact.cjs
new file mode 100644
index 000000000..1d3620e88
--- /dev/null
+++ b/.github/scripts/wait-for-workflow-artifact.cjs
@@ -0,0 +1,127 @@
+'use strict';
+
+const DEFAULT_POLL_INTERVAL_MS = 30_000;
+const DEFAULT_TIMEOUT_MS = 110 * 60_000;
+
+async function pollWorkflowArtifact({
+ artifactName,
+ listArtifacts,
+ getTargetJob = async () => null,
+ getWorkflowRun,
+ now = Date.now,
+ sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)),
+ pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,
+ timeoutMs = DEFAULT_TIMEOUT_MS,
+}) {
+ const deadline = now() + timeoutMs;
+
+ while (true) {
+ const artifacts = await listArtifacts();
+ const artifact = artifacts.find(
+ (candidate) => candidate.name === artifactName && candidate.expired !== true
+ );
+ if (artifact) {
+ return {
+ artifactAvailable: true,
+ conclusion: '',
+ };
+ }
+
+ const targetJob = await getTargetJob();
+ if (targetJob?.status === 'completed') {
+ return {
+ artifactAvailable: false,
+ conclusion: targetJob.conclusion || 'failure',
+ };
+ }
+
+ const workflowRun = await getWorkflowRun();
+ if (workflowRun.status === 'completed') {
+ return {
+ artifactAvailable: false,
+ conclusion: workflowRun.conclusion || 'failure',
+ };
+ }
+
+ const remainingMs = deadline - now();
+ if (remainingMs <= 0) {
+ return {
+ artifactAvailable: false,
+ conclusion: 'timed_out',
+ };
+ }
+ await sleep(Math.min(pollIntervalMs, remainingMs));
+ }
+}
+
+async function waitForWorkflowArtifact({
+ github,
+ context,
+ core,
+ artifactName,
+ targetJobName,
+ pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,
+ timeoutMs = DEFAULT_TIMEOUT_MS,
+}) {
+ const run = context.payload.workflow_run;
+ if (!run?.id) {
+ throw new Error('workflow_run.id is required');
+ }
+ if (!artifactName) {
+ throw new Error('artifactName is required');
+ }
+
+ const owner = context.repo.owner;
+ const repo = context.repo.repo;
+ const runId = run.id;
+ const result = await pollWorkflowArtifact({
+ artifactName,
+ pollIntervalMs,
+ timeoutMs,
+ listArtifacts: async () => {
+ const response = await github.rest.actions.listWorkflowRunArtifacts({
+ owner,
+ repo,
+ run_id: runId,
+ per_page: 100,
+ });
+ return response.data.artifacts;
+ },
+ getTargetJob: async () => {
+ if (!targetJobName) {
+ return null;
+ }
+ const response = await github.rest.actions.listJobsForWorkflowRun({
+ owner,
+ repo,
+ run_id: runId,
+ filter: 'latest',
+ per_page: 100,
+ });
+ return response.data.jobs.find((job) => job.name === targetJobName) || null;
+ },
+ getWorkflowRun: async () => {
+ const response = await github.rest.actions.getWorkflowRun({
+ owner,
+ repo,
+ run_id: runId,
+ });
+ return response.data;
+ },
+ });
+
+ const runUrl = run.html_url || `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
+ core.setOutput('artifact_available', String(result.artifactAvailable));
+ core.setOutput('conclusion', result.conclusion);
+ core.setOutput('run_id', String(runId));
+ core.setOutput('run_url', runUrl);
+
+ if (!result.artifactAvailable) {
+ core.notice(
+ `The target job or workflow run ${runId} finished, or the wait timed out, before ${artifactName} was uploaded.`
+ );
+ }
+}
+
+module.exports = waitForWorkflowArtifact;
+module.exports.pollWorkflowArtifact = pollWorkflowArtifact;
diff --git a/.github/scripts/wait-for-workflow-artifact.test.cjs b/.github/scripts/wait-for-workflow-artifact.test.cjs
new file mode 100644
index 000000000..d4d1ec072
--- /dev/null
+++ b/.github/scripts/wait-for-workflow-artifact.test.cjs
@@ -0,0 +1,91 @@
+'use strict';
+
+const assert = require('node:assert/strict');
+const test = require('node:test');
+
+const {
+ pollWorkflowArtifact,
+} = require('./wait-for-workflow-artifact.cjs');
+
+test('returns as soon as the requested artifact is available', async () => {
+ let workflowLookups = 0;
+ const result = await pollWorkflowArtifact({
+ artifactName: 'benchmark-results',
+ listArtifacts: async () => [
+ { name: 'other-results', expired: false },
+ { name: 'benchmark-results', expired: false },
+ ],
+ getWorkflowRun: async () => {
+ workflowLookups += 1;
+ return { status: 'in_progress', conclusion: null };
+ },
+ });
+
+ assert.deepEqual(result, { artifactAvailable: true, conclusion: '' });
+ assert.equal(workflowLookups, 0);
+});
+
+test('waits for an artifact while the workflow is running', async () => {
+ let artifactLookups = 0;
+ let sleeps = 0;
+ const result = await pollWorkflowArtifact({
+ artifactName: 'benchmark-results',
+ listArtifacts: async () => {
+ artifactLookups += 1;
+ return artifactLookups === 1
+ ? []
+ : [{ name: 'benchmark-results', expired: false }];
+ },
+ getWorkflowRun: async () => ({ status: 'in_progress', conclusion: null }),
+ now: () => 0,
+ sleep: async () => {
+ sleeps += 1;
+ },
+ });
+
+ assert.deepEqual(result, { artifactAvailable: true, conclusion: '' });
+ assert.equal(sleeps, 1);
+});
+
+test('reports a terminal workflow that never uploaded the artifact', async () => {
+ const result = await pollWorkflowArtifact({
+ artifactName: 'benchmark-results',
+ listArtifacts: async () => [],
+ getWorkflowRun: async () => ({ status: 'completed', conclusion: 'failure' }),
+ });
+
+ assert.deepEqual(result, { artifactAvailable: false, conclusion: 'failure' });
+});
+
+test('does not wait for unrelated jobs after the target job finishes', async () => {
+ let workflowLookups = 0;
+ const result = await pollWorkflowArtifact({
+ artifactName: 'benchmark-results',
+ listArtifacts: async () => [],
+ getTargetJob: async () => ({ status: 'completed', conclusion: 'skipped' }),
+ getWorkflowRun: async () => {
+ workflowLookups += 1;
+ return { status: 'in_progress', conclusion: null };
+ },
+ });
+
+ assert.deepEqual(result, { artifactAvailable: false, conclusion: 'skipped' });
+ assert.equal(workflowLookups, 0);
+});
+
+test('ignores expired artifacts and eventually times out', async () => {
+ let currentTime = 0;
+ const result = await pollWorkflowArtifact({
+ artifactName: 'benchmark-results',
+ listArtifacts: async () => [{ name: 'benchmark-results', expired: true }],
+ getWorkflowRun: async () => ({ status: 'in_progress', conclusion: null }),
+ now: () => currentTime,
+ sleep: async (milliseconds) => {
+ currentTime += milliseconds;
+ },
+ pollIntervalMs: 10,
+ timeoutMs: 20,
+ });
+
+ assert.deepEqual(result, { artifactAvailable: false, conclusion: 'timed_out' });
+});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6d89249a1..4334daa74 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -218,6 +218,8 @@ jobs:
- name: Test Spider harness
working-directory: moli-benchmark/browser-spider-local
run: npm test
+ - name: Test trusted report helpers
+ run: node --test .github/scripts/wait-for-workflow-artifact.test.cjs
build-release-head:
name: Build release · HEAD
diff --git a/.github/workflows/sequential-navigation-soak-comment.yml b/.github/workflows/sequential-navigation-soak-comment.yml
index ba09c8c48..44c2ce636 100644
--- a/.github/workflows/sequential-navigation-soak-comment.yml
+++ b/.github/workflows/sequential-navigation-soak-comment.yml
@@ -3,11 +3,15 @@ name: Sequential Navigation Soak Report
on:
workflow_run:
workflows: [CI]
- types: [completed]
+ types: [in_progress]
-# This workflow runs from the default branch. It never executes the measured
-# PR binary and only renders bounded numeric fields from the downloaded artifact.
-# The rendered report is published both as an Actions summary and a PR comment.
+concurrency:
+ group: sequential-navigation-soak-report-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.id }}
+ cancel-in-progress: true
+
+# This trusted workflow starts with CI, then waits only for the immutable v4
+# artifact. It runs from the default branch, never executes PR code, and renders
+# only bounded numeric fields into an Actions summary and an upserted PR comment.
permissions:
actions: read
contents: read
@@ -18,11 +22,10 @@ jobs:
name: Publish soak report
if: >-
github.event.workflow_run.event == 'pull_request' &&
- github.event.workflow_run.conclusion != 'cancelled' &&
github.event.workflow_run.pull_requests[0].head.repo.id == github.event.repository.id &&
github.event.workflow_run.actor.login != 'dependabot[bot]'
runs-on: ubuntu-latest
- timeout-minutes: 10
+ timeout-minutes: 120
steps:
- name: Checkout trusted comment renderer
uses: actions/checkout@v4
@@ -30,7 +33,28 @@ jobs:
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
+ - name: Wait for soak evidence
+ id: wait
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
+ env:
+ ARTIFACT_NAME: sequential-navigation-soak-results
+ TARGET_JOB_NAME: Sequential navigation soak · 200 A/B
+ with:
+ retries: 3
+ script: |
+ const waitForWorkflowArtifact = require(
+ './.github/scripts/wait-for-workflow-artifact.cjs'
+ );
+ await waitForWorkflowArtifact({
+ github,
+ context,
+ core,
+ artifactName: process.env.ARTIFACT_NAME,
+ targetJobName: process.env.TARGET_JOB_NAME,
+ });
+
- name: Download soak evidence
+ if: steps.wait.outputs.artifact_available == 'true'
id: evidence
continue-on-error: true
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
@@ -38,14 +62,15 @@ jobs:
name: sequential-navigation-soak-results
path: sequential-navigation-soak-results
github-token: ${{ secrets.GITHUB_TOKEN }}
- run-id: ${{ github.event.workflow_run.id }}
+ run-id: ${{ steps.wait.outputs.run_id }}
- name: Render trusted PR comment
+ if: steps.wait.outputs.conclusion != 'cancelled'
id: render
env:
PYTHONPATH: moli-benchmark
- RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
- CONCLUSION: ${{ github.event.workflow_run.conclusion }}
+ RUN_URL: ${{ steps.wait.outputs.run_url }}
+ CONCLUSION: ${{ steps.wait.outputs.conclusion || 'failure' }}
EVIDENCE_OUTCOME: ${{ steps.evidence.outcome }}
run: |
if [[ "$EVIDENCE_OUTCOME" == success && -f sequential-navigation-soak-results/comparison.json ]]; then
@@ -70,9 +95,11 @@ jobs:
fi
- name: Publish Actions report
+ if: steps.wait.outputs.conclusion != 'cancelled'
run: cat sequential-navigation-soak-comment.md >> "$GITHUB_STEP_SUMMARY"
- name: Post PR soak comment
+ if: steps.wait.outputs.conclusion != 'cancelled'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
env:
COMMENT_PATH: sequential-navigation-soak-comment.md
diff --git a/.github/workflows/spider-bench-comment.yml b/.github/workflows/spider-bench-comment.yml
index b36cbb498..e53bddf89 100644
--- a/.github/workflows/spider-bench-comment.yml
+++ b/.github/workflows/spider-bench-comment.yml
@@ -3,11 +3,15 @@ name: Spider Bench Report
on:
workflow_run:
workflows: [CI]
- types: [completed]
+ types: [in_progress]
-# This trusted workflow runs from the default branch. It never executes code
-# from the PR checkout and only renders bounded numeric fields from the artifact.
-# The rendered report is published both as an Actions summary and a PR comment.
+concurrency:
+ group: spider-bench-report-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.id }}
+ cancel-in-progress: true
+
+# This trusted workflow starts with CI, then waits only for the immutable v4
+# artifact. It runs from the default branch, never executes PR code, and renders
+# only bounded numeric fields into an Actions summary and a PR comment.
permissions:
actions: read
contents: read
@@ -18,11 +22,10 @@ jobs:
name: Publish benchmark report
if: >-
github.event.workflow_run.event == 'pull_request' &&
- github.event.workflow_run.conclusion != 'cancelled' &&
github.event.workflow_run.pull_requests[0].head.repo.id == github.event.repository.id &&
github.event.workflow_run.actor.login != 'dependabot[bot]'
runs-on: ubuntu-latest
- timeout-minutes: 10
+ timeout-minutes: 120
steps:
- name: Checkout trusted comment renderer
uses: actions/checkout@v4
@@ -30,7 +33,28 @@ jobs:
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
+ - name: Wait for benchmark evidence
+ id: wait
+ uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
+ env:
+ ARTIFACT_NAME: spider-bench-results
+ TARGET_JOB_NAME: Spider public-web A/B
+ with:
+ retries: 3
+ script: |
+ const waitForWorkflowArtifact = require(
+ './.github/scripts/wait-for-workflow-artifact.cjs'
+ );
+ await waitForWorkflowArtifact({
+ github,
+ context,
+ core,
+ artifactName: process.env.ARTIFACT_NAME,
+ targetJobName: process.env.TARGET_JOB_NAME,
+ });
+
- name: Download benchmark evidence
+ if: steps.wait.outputs.artifact_available == 'true'
id: evidence
continue-on-error: true
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
@@ -38,18 +62,20 @@ jobs:
name: spider-bench-results
path: spider-bench-results
github-token: ${{ secrets.GITHUB_TOKEN }}
- run-id: ${{ github.event.workflow_run.id }}
+ run-id: ${{ steps.wait.outputs.run_id }}
- name: Install Node.js
+ if: steps.wait.outputs.conclusion != 'cancelled'
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 24.15.0
- name: Render trusted PR comment
+ if: steps.wait.outputs.conclusion != 'cancelled'
id: render
env:
- RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
- CONCLUSION: ${{ github.event.workflow_run.conclusion }}
+ RUN_URL: ${{ steps.wait.outputs.run_url }}
+ CONCLUSION: ${{ steps.wait.outputs.conclusion || 'failure' }}
EVIDENCE_OUTCOME: ${{ steps.evidence.outcome }}
run: |
if [[ "$EVIDENCE_OUTCOME" == success && -f spider-bench-results/comparison.json ]]; then
@@ -68,9 +94,11 @@ jobs:
fi
- name: Publish Actions report
+ if: steps.wait.outputs.conclusion != 'cancelled'
run: cat spider-bench-comment.md >> "$GITHUB_STEP_SUMMARY"
- name: Post PR benchmark comment
+ if: steps.wait.outputs.conclusion != 'cancelled'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
env:
COMMENT_PATH: spider-bench-comment.md