Skip to content
Merged
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
49 changes: 49 additions & 0 deletions scripts/check-agent-session-manifests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,54 @@
* Default targets (when no explicit args given):
* - docs/schemas/examples/**\/*.json
* - tests/fixtures/ ** /agent-session-manifest*.json and *.md
* - artifacts/agent-session-manifest-ci.json (production artifact — see production gate topology below)
*
* Explicit targets: any glob patterns or file paths passed as CLI args
* If explicit targets resolve to 0 files: exit 1 (empty-target green is forbidden)
*
* Exit codes:
* 0: All manifests pass validation
* 1: One or more manifests failed, or 0 targets found for explicit arg
*
* ----------------------------------------------------------------------------
* production.gate|production gate topology (Plan A (adopted in #434))
* ----------------------------------------------------------------------------
* Plan A (adopted in #434): `.github/workflows/session-manifest.yml` is the source of truth
* for the production gate.
* - session-manifest.yml runs generate -> validate -> upload in sequence.
* - ci.yml does not own the production gate (Plan A adopted). The alternative where
* ci.yml independently handles manifest generation, validation, and upload (Plan B)
* was not adopted.
*
* session-manifest.yml production gate configuration
* (must be updated together when changing):
* - generate: node scripts/generate-session-manifest.mjs ... > artifacts/agent-session-manifest-ci.json
* - validate: pnpm manifest:check artifacts/agent-session-manifest-ci.json
* - upload: actions/upload-artifact path: artifacts/agent-session-manifest-ci.json
*
* IMPORTANT: When changing the artifact path, the following 4 locations
* must all be updated together:
* - session-manifest.yml: generate step
* - session-manifest.yml: validate step
* - session-manifest.yml: upload step
* - defaultPatterns in this file
* Updating only one location results in a silent no-op or validation bypass.
*
* Artifact upload constraints (must be maintained in session-manifest.yml):
* upload step: both if-no-files-found|retention-days constraints must be maintained
* - if-no-files-found: error (fail CI if upload target is empty)
* - retention-days: 7 (retain for 7 days)
* permissions: contents: read only (minimum read-only permission)
* pull_request_target is not used (avoids elevated permissions and secrets exposure)
* secrets.* are not used
*
* Issue #402 AC8 specified a 'private-agent-session-manifest' prefix requirement,
* which was not adopted in PR #426. Current artifact name follows the convention
* established in PR #426: 'agent-session-manifest-${{ github.run_id }}'.
*
* Runtime environment (CI environment assumed):
* Node 22|pnpm 11|node-version: '22' — assumes session-manifest.yml node-version: '22', pnpm: 11.1.2
* ----------------------------------------------------------------------------
*/

import { readFileSync, existsSync } from 'fs'
Expand Down Expand Up @@ -310,10 +351,18 @@ async function main() {
const args = rawArgs.filter(a => !a.startsWith('--'))
const isExplicit = args.length > 0

// Production artifact path (Plan A: session-manifest.yml is the source of truth for the production gate)
// In CI, session-manifest.yml calls this script with an explicit target, so this entry
// serves only as a fallback for local developers in defaultPatterns.
// NOTE: If artifacts/agent-session-manifest-ci.json does not exist (e.g., local environment),
// expandGlobs will skip it (consistent with the 0-file-allowed behavior of default patterns).
// In CI, session-manifest.yml always validates via an explicit target call,
// so this does not result in a silent no-op (session-manifest.yml is the production gate source of truth).
const defaultPatterns = [
'docs/schemas/examples/**/*.json',
'tests/fixtures/agent-session-manifest/valid-*.json',
'tests/fixtures/agent-session-manifest/valid-*.md',
'artifacts/agent-session-manifest-ci.json', // production artifact (generated by session-manifest.yml)
]

const patterns = isExplicit ? args : defaultPatterns
Expand Down