This document covers how to test the action locally and in CI before publishing.
Run all unit tests with:
npm testRun in watch mode during development:
npm run test:watchThe test suite covers:
token-extractor.test.ts— JSON and regex-based token extraction, priority logic, edge casescontext.test.ts— GitHub event → trigger type mapping, trigger ref extraction for all event typescomment.test.ts— Markdown comment formatting, status emojis, cost formatting, multi-run accumulationingest.test.ts— API client success/failure handling, retry logic, Authorization header
To test the full compiled action against a real or mocked AgentMeter API:
npm run buildThis compiles TypeScript to dist/ then bundles with ncc into dist/index.js.
Create a test event payload file first:
cat > /tmp/event.json << 'EOF'
{
"action": "labeled",
"issue": {
"number": 1,
"pull_request": null
},
"label": {
"name": "agent"
}
}
EOFThen export the required env vars:
export INPUT_API_KEY="am_sk_your_key_here"
export INPUT_MODEL="claude-sonnet-4-5"
export INPUT_STATUS="success"
export INPUT_ENGINE="claude"
export INPUT_POST_COMMENT="false" # disable comment posting for local tests
export INPUT_API_URL="https://agentmeter.app" # or your local API URL
# GitHub Actions context variables
export GITHUB_REPOSITORY="yourorg/your-repo"
export GITHUB_RUN_ID="12345678"
export GITHUB_WORKFLOW="agent-implement"
export GITHUB_EVENT_NAME="issues"
export GITHUB_EVENT_PATH="/tmp/event.json"
export GITHUB_TOKEN="your_github_pat" # optional, only needed if post_comment=truenode dist/index.jsYou should see output like:
::set-output name=run_id::clx1abc...
::set-output name=total_cost_usd::0.00
::set-output name=dashboard_url::https://agentmeter.app/dashboard/runs/clx1abc...
To test token extraction from JSON output:
export INPUT_AGENT_OUTPUT='{"usage":{"input_tokens":1000,"output_tokens":500,"cache_read_input_tokens":200,"cache_creation_input_tokens":100}}'
node dist/index.jsOr with explicit token counts:
export INPUT_INPUT_TOKENS="5000"
export INPUT_OUTPUT_TOKENS="2000"
export INPUT_CACHE_READ_TOKENS="15000"
export INPUT_CACHE_WRITE_TOKENS="3000"
export INPUT_TURNS="12"
node dist/index.jsIf you have the AgentMeter web app running locally:
export INPUT_API_URL="http://localhost:3000"
export INPUT_API_KEY="am_sk_your_local_key"
node dist/index.jsThe action will POST to http://localhost:3000/api/ingest.
To test that the comment posts correctly to a real GitHub issue or PR:
- Set
INPUT_POST_COMMENT="true" - Set
GITHUB_TOKENto a PAT withissues:writepermission on the target repo - Set
GITHUB_EVENT_NAMEtoissuesand ensure the event payload has a real issue number - Run
node dist/index.js
Check the GitHub issue for the posted comment.
The CI workflow (.github/workflows/ci.yml) runs on every push and PR:
npm run lint— Biome lintingnpm run type-check— TypeScript strict mode checknpm test— Full test suite
The build workflow (.github/workflows/build.yml) runs on pushes to main:
- Builds the dist bundle
- Auto-commits any changes to
dist/(required for the action to work when referenced viauses: foo-software/agentmeter-action@v1)
- Ensure all tests pass:
npm test - Run type check:
npm run type-check - Build the bundle:
npm run build - Commit everything including
dist/ - Push to
main - Create a GitHub release with a semver tag:
v1.0.0 - Also update the major version tag:
git tag -f v1 && git push -f origin v1 - In the GitHub release UI, check "Publish this Action to GitHub Marketplace"
Note: The
dist/directory must be committed to the repository. GitHub Actions checks out the repo at the referenced tag and runsdist/index.jsdirectly — it does not runnpm installornpm run build.