Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Generated by `npm run bundle`: collapsed in GitHub diffs and shown as binary by git diff.
.github/cli/apify-test-tools.mjs linguist-generated=true -diff
.github/scripts/run-with-apify-tokens.mjs linguist-generated=true -diff
.github/scripts/*.mjs linguist-generated=true -diff
52 changes: 52 additions & 0 deletions .github/actions/failure-signatures/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Match failures to known issues
description: >-
`match` matches the run's failing tests to open issues by failure signature, `record` records the signatures that
matched nothing on the issue that now covers them. See workflow-scripts-src/failure-signatures.ts.
inputs:
mode:
description: '`match` or `record`'
required: true
new-issue-number:
description: The issue the investigation opened, if any, for `record`.
required: false
default: ''
outputs:
all-known:
description: '`true` when every failure matches an open issue'
value: ${{ steps.script.outputs.all-known }}
note:
description: When only some failures match, which issues cover them and which failing tests are left
value: ${{ steps.script.outputs.note }}

# The script ships with this action as a bundle (npm run bundle), so nothing is checked out or installed.
runs:
using: 'composite'
steps:
- name: Run the script
id: script
uses: actions/github-script@v9
env:
MODE: ${{ inputs.mode }}
NEW_ISSUE_NUMBER: ${{ inputs.new-issue-number }}
MATCHES_PATH: ${{ runner.temp }}/failure-signatures.json
SCRIPT_PATH: ${{ github.action_path }}/../../scripts/failure-signatures.mjs
with:
script: |
const { matchKnownFailures, recordSignatures } = await import(process.env.SCRIPT_PATH);
const workspace = process.env.GITHUB_WORKSPACE;
const params = { github, context, core, matchesPath: process.env.MATCHES_PATH };
if (process.env.MODE === 'match') {
await matchKnownFailures({
...params,
reportPath: `${workspace}/vitest-results/test-report.json`,
duplicatesPath: `${workspace}/duplicate-of.txt`,
});
} else if (process.env.MODE === 'record') {
await recordSignatures({
...params,
dedupePath: `${workspace}/dedupe.json`,
newIssueNumber: Number(process.env.NEW_ISSUE_NUMBER) || undefined,
});
} else {
throw new Error(`Unsupported mode '${process.env.MODE}'. Use 'match' or 'record'.`);
}
7 changes: 7 additions & 0 deletions .github/scripts/failure-signatures.mjs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this to the no diff thing. We did the same to the other files that we compile like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ b1709f7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/_check_code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
- name: Check the bundle is up to date
run: |
npm run bundle
if ! git diff --quiet -- .github/cli/ .github/scripts/run-with-apify-tokens.mjs .github/scripts/humanize-duty.mjs; then
if ! git diff --quiet -- .github/cli/ '.github/scripts/*.mjs'; then
echo "::error::A CLI or workflow script bundle is out of date. Run \`npm run bundle\` and commit the result."
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ name: 'Platform tests: Claude failure investigation'

# Reusable workflow that uses Claude Code to investigate a failing E2E platform test.
#
# 1. A first check works out what broke and whether open issues already cover it, and updates the recurrence
# comment on each covering issue. If they cover everything, the job stops there.
# 2. Otherwise the main model investigates what isn't covered and opens an issue with its findings.
# 1. A script matches the failures to open issues by the failure signatures the issues recorded, with no model.
# 2. For what it can't match, a first check works out what broke and whether open issues already cover it.
# Each covering issue gets its recurrence comment updated. If they cover everything, the job stops there.
# 3. Otherwise the main model investigates what isn't covered and opens an issue with its findings.
# 4. The covering issues record the signatures of the failures they cover, so step 1 matches them next time.
#
# With `humanize_duty` set, a new issue also records the developer who rewrites it in plain language: the
# next individual user on the `*` rule of the repo's CODEOWNERS, in turn. `label` labels the issue
Expand Down Expand Up @@ -168,9 +170,17 @@ jobs:
echo 'disallowed-tools=mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet'
} >> "$GITHUB_OUTPUT"

- name: Match the failures to known issues
id: known
if: hashFiles('vitest-results/test-report.json') != ''
continue-on-error: true
uses: $/.github/actions/failure-signatures
with:
mode: match

- name: Check for existing issues
id: dedupe
if: hashFiles('vitest-results/test-report.json') != ''
if: hashFiles('vitest-results/test-report.json') != '' && steps.known.outputs.all-known != 'true'
continue-on-error: true
uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213
env:
Expand All @@ -180,9 +190,11 @@ jobs:
prompt: |
E2E platform tests failed in workflow run ${{ github.run_id }} of this repo. Its test report is at $GITHUB_WORKSPACE/vitest-results/test-report.json: it lists each test with its status and failure messages, plus any errors outside the tests.

${{ steps.known.outputs.note }}

The tests overlap a lot, so one bug usually fails several of them. Work out what actually broke, the distinct root causes behind these failures, and whether an open issue in this repo already covers each one. List the open issues with `gh issue list --state open --limit 200 --json number,title,body,labels`, focusing on those labeled `claude`, and read any you need in full with `gh issue view`. An issue covers a failure when it describes the same root cause, no matter which tests it mentions. If the failure messages aren't enough to tell, look at the failing Actor runs with the Apify tools. When unsure, treat the failure as not covered: a missed duplicate costs one investigation, a wrong match hides a bug.

Don't investigate further and don't change anything on GitHub. Write your answer to $GITHUB_WORKSPACE/dedupe.json as `{"issues": [<numbers of the open issues that cover a failure in this run>], "uncovered": "<what broke that no open issue covers, in a sentence or two, or an empty string if they cover everything>"}`.
Don't investigate further and don't change anything on GitHub. Write your answer to $GITHUB_WORKSPACE/dedupe.json as `{"issues": [<numbers of the open issues that cover a failure in this run>], "tests": {"<issue number>": [<names of the failing tests that issue covers, exactly as in the report, or "(outside any test)" for the report's errors>]}, "uncovered": "<what broke that no open issue covers, in a sentence or two, or an empty string if they cover everything>"}`.
github_token: ${{ secrets.GITHUB_TOKEN }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: |
Expand All @@ -199,15 +211,22 @@ jobs:

# Reads the check's answer:
#
# 1. Everything covered: skip the investigation.
# 1. Everything covered, by recorded signatures or by the check: skip the investigation.
# 2. Part covered: tell the main model which part, so it investigates only the rest.
# 3. No usable answer: investigate everything.
- name: Decide whether to investigate
id: duplicates
if: ${{ !cancelled() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ALL_KNOWN: ${{ steps.known.outputs.all-known }}
run: |
if [ "$ALL_KNOWN" = 'true' ]; then
echo "all-duplicates=true" >> "$GITHUB_OUTPUT"
echo "Every failure matches the signatures recorded on open issues, skipping the investigation"
exit 0
fi

answer="$GITHUB_WORKSPACE/dedupe.json"
issues='[]'
uncovered='no answer from the check'
Expand All @@ -228,24 +247,26 @@ jobs:
echo "::warning::The check matched the failure to $dropped_refs, which aren't open issues"
uncovered="${uncovered:+$uncovered }Also what the check matched to $dropped_refs, which aren't open issues."
fi
refs=$(jq -r 'map("#\(.)") | join(", ")' <<< "$issues")

if [ "$(jq length <<< "$issues")" -gt 0 ]; then
jq -r '.[]' <<< "$issues" > "$GITHUB_WORKSPACE/duplicate-of.txt"
jq -r '.[]' <<< "$issues" >> "$GITHUB_WORKSPACE/duplicate-of.txt"
fi
if [ "$(jq length <<< "$issues")" -gt 0 ] && [ -z "$(tr -d '[:space:]' <<< "$uncovered")" ]; then
# Includes the issues the signatures matched, which the check may leave out of its answer. The file
# is missing when no issue covers anything, which would otherwise fail the step and skip the
# investigation.
covering_refs=$(jq -Rrn '[inputs | tonumber? ] | unique | map("#\(.)") | join(", ")' "$GITHUB_WORKSPACE/duplicate-of.txt" 2> /dev/null || true)
if [ -n "$covering_refs" ] && [ -z "$(tr -d '[:space:]' <<< "$uncovered")" ]; then
echo "all-duplicates=true" >> "$GITHUB_OUTPUT"
echo "Open issues $refs already cover the failure, skipping the investigation"
echo "Open issues $covering_refs already cover the failure, skipping the investigation"
exit 0
fi

echo "all-duplicates=false" >> "$GITHUB_OUTPUT"
echo "Covered by: ${refs:-none}. Not covered: $uncovered"
if [ "$(jq length <<< "$issues")" -gt 0 ]; then
echo "Covered by: ${covering_refs:-none}. Not covered: $uncovered"
if [ -n "$covering_refs" ]; then
delimiter="EOF_$(openssl rand -hex 8)"
{
echo "note<<$delimiter"
echo "A first check found that open issues $refs already cover part of this failure. Read them and investigate only what they don't explain."
echo "A first check found that open issues $covering_refs already cover part of this failure. Read them and investigate only what they don't explain."
echo "$delimiter"
} >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -328,6 +349,14 @@ jobs:
echo "No issue created (duplicate skipped)"
fi

- name: Record the failure signatures on the covering issues
if: ${{ !cancelled() && steps.known.outcome == 'success' }}
continue-on-error: true
uses: $/.github/actions/failure-signatures
with:
mode: record
new-issue-number: ${{ steps.issue.outputs.number }}

# Adds the "claude" label for visibility. Scheduled runs lack the permissions to trigger other
# workflows, so this doesn't start the Claude workflow on the issue.
- name: Add Claude label to issue
Expand Down
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
echo "pre-commit: typechecking, linting, testing, checking code formatting, checking for unused exports & validating schemas"


# The workflows run the CLI, token wrapper and humanize-duty script from these bundles, so they ship
# The workflows run the CLI, token wrapper and other workflow scripts from these bundles, so they ship
# with every commit that changes their sources or dependencies.
npm run -s bundle
git add .github/cli/apify-test-tools.mjs .github/scripts/run-with-apify-tokens.mjs .github/scripts/humanize-duty.mjs
git add .github/cli/apify-test-tools.mjs '.github/scripts/*.mjs'

npm test
npm run format:check
Expand Down
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ test/fixtures

# Generated by `npm run bundle`
.github/cli/
.github/scripts/run-with-apify-tokens.mjs
.github/scripts/humanize-duty.mjs
.github/scripts/*.mjs
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Consumers pin `@workflows-v0`, not `@master`. See [Versioning and releases](#ver
pushing workflow changes.

The reusable workflows load the composite actions with `uses: $/.github/actions/checkout-restore-dependencies` (and
`$/.github/actions/humanize-duty`), never `apify/apify-test-tools/...@workflows-v0`. `$/` is the
[self-repository syntax](https://github.blog/changelog/2026-07-30-reference-same-repository-actions-with-self-repository-syntax/):
`$/.github/actions/humanize-duty`, `$/.github/actions/failure-signatures`), never
`apify/apify-test-tools/...@workflows-v0`. `$/` is the [self-repository syntax](https://github.blog/changelog/2026-07-30-reference-same-repository-actions-with-self-repository-syntax/):
it resolves to this repo at the commit the workflow was called at. A hardcoded tag would hand a caller pinned to an
older SHA, or to a branch, the action and CLI from the tag instead of from the commit they asked for.

Expand Down
Loading