assay-cli 7.0.4

Policy-as-code gate for MCP agent tool calls, with verifiable evidence and Linux kernel enforcement.
pub const CI_EVAL_YAML: &str = r#"configVersion: 1
suite: "ci_smoke"
model: "trace"
tests:
  - id: "ci_smoke_regex"
    input:
      prompt: "ci_regex"
    expected:
      type: regex_match
      pattern: "Hello\\s+CI"
      flags: ["i"]
  - id: "ci_smoke_schema"
    input:
      prompt: "ci_schema"
    expected:
      type: json_schema
      json_schema: "{}"
      schema_file: "schemas/ci_answer.schema.json"
  - id: "ci_smoke_semantic"
    input:
      prompt: "ci_semantic"
    expected:
      type: semantic_similarity_to
      semantic_similarity_to: "Hello Semantic"
      min_score: 0.99
"#;

pub const CI_SCHEMA_JSON: &str = r#"{
  "type": "object",
  "required": ["answer"],
  "properties": {
    "answer": { "type": "string" }
  },
  "additionalProperties": false
}"#;

pub const CI_TRACES_JSONL: &str = r#"{"type":"episode_start","episode_id":"ci_1","timestamp":0,"input":{"prompt":"ci_regex"},"meta":{}}
{"type":"step","episode_id":"ci_1","step_id":"ci_1-step-0","idx":0,"timestamp":1,"kind":"llm_completion","name":"model","content":"hello   ci","content_sha256":"32213cac22371473edace43b0f21bd109100f6160cc344557aed419e5dcbf26a","truncations":[],"meta":{"gen_ai.response.model":"trace","gen_ai.provider.name":"trace"}}
{"type":"episode_end","episode_id":"ci_1","timestamp":2,"final_output":null}
{"type":"episode_start","episode_id":"ci_2","timestamp":0,"input":{"prompt":"ci_schema"},"meta":{}}
{"type":"step","episode_id":"ci_2","step_id":"ci_2-step-0","idx":0,"timestamp":1,"kind":"llm_completion","name":"model","content":"{\"answer\":\"ok\"}","content_sha256":"2b82c37965faf7db40dae134cc94675e0f6dac048a0173a1861b6ed1b8db7d5b","truncations":[],"meta":{"gen_ai.response.model":"trace","gen_ai.provider.name":"trace"}}
{"type":"episode_end","episode_id":"ci_2","timestamp":2,"final_output":null}
{"type":"episode_start","episode_id":"ci_3","timestamp":0,"input":{"prompt":"ci_semantic"},"meta":{"assay":{"embeddings":{"model":"trace-embed","response":[1.0,0.0,0.0],"reference":[1.0,0.0,0.0],"source_response":"trace","source_reference":"trace"}}}}
{"type":"step","episode_id":"ci_3","step_id":"ci_3-step-0","idx":0,"timestamp":1,"kind":"llm_completion","name":"model","content":"Hello Semantic","content_sha256":"66310524718ae538642d3d1890acba16c92c4e0f4467aa579dfab1ce80a0b0d3","truncations":[],"meta":{"gen_ai.response.model":"trace","gen_ai.provider.name":"trace"}}
{"type":"episode_end","episode_id":"ci_3","timestamp":2,"final_output":null}
"#;

pub const HELLO_EVAL_YAML: &str = r#"configVersion: 1
suite: "hello_smoke"
model: "trace"
tests:
  - id: "hello_smoke_regex"
    input:
      prompt: "hello_prompt"
    expected:
      type: regex_match
      pattern: "Hello\\s+Assay"
      flags: ["i"]
"#;

pub const HELLO_TRACES_JSONL: &str = r#"{"type":"episode_start","episode_id":"hello_1","timestamp":0,"input":{"prompt":"hello_prompt"},"meta":{}}
{"type":"step","episode_id":"hello_1","step_id":"hello_1-step-0","idx":0,"timestamp":1,"kind":"llm_completion","name":"model","content":"Hello Assay","content_sha256":"0a2645f7cd6ee9ef61a14084a1160319ad537358558ddfbcf8d868ae1d7aabbe","truncations":[],"meta":{"gen_ai.response.model":"trace","gen_ai.provider.name":"trace"}}
{"type":"episode_end","episode_id":"hello_1","timestamp":2,"final_output":null}
"#;

/// Blessed CI workflow template (v2)
/// Generated by `assay init --ci` and `assay init-ci --provider github`
///
/// This template uses `assay-action` to install the CLI, then runs `assay ci`
/// directly for the eval-based gate, and finally uploads SARIF results to GitHub Code Scanning.
/// Canonical marketplace slug: `Rul1an/assay-action@v3`.
/// See: <https://github.com/Rul1an/assay-action>
pub const CI_WORKFLOW_YML: &str = r#"name: Assay Gate
on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read
  pull-requests: write   # Required for PR comment
  security-events: write # Required for SARIF upload

jobs:
  assay:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 (Pinned for supply-chain security)

      - name: Setup Assay
        uses: Rul1an/assay-action@v3 # For strict supply-chain pinning, use a full commit SHA. Exact tags (e.g. v3.1.0) are less strict.

      - name: Run Assay Tests
        run: assay ci --config ci-eval.yaml --trace-file traces/ci.jsonl --sarif .assay/reports/sarif.json --junit .assay/reports/junit.xml --pr-comment .assay/reports/pr-comment.md

      - name: Upload SARIF
        # Skip on fork PRs to prevent permission errors, and ensure file exists
        if: always() && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && hashFiles('.assay/reports/sarif.json') != ''
        # Pin to SHA for supply-chain security (v3.28.10)
        uses: github/codeql-action/upload-sarif@b20883b0cd1f46c72ae0ba6d1090936928f9fa30
        with:
          sarif_file: .assay/reports/sarif.json
          category: assay-gate

      - name: Find existing PR comment
        id: find-comment
        if: github.event_name == 'pull_request' && hashFiles('.assay/reports/pr-comment.md') != ''
        uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
        continue-on-error: true
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: '<!-- assay-governance-report -->'

      - name: Post governance summary
        if: github.event_name == 'pull_request' && hashFiles('.assay/reports/pr-comment.md') != ''
        uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
        continue-on-error: true
        with:
          comment-id: ${{ steps.find-comment.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          edit-mode: replace
          body-path: .assay/reports/pr-comment.md

"#;

/// GitLab CI template for assay gate. Written by `assay init --ci gitlab` and
/// `assay init-ci --provider gitlab`.
pub const GITLAB_CI_YML: &str = r#"assay:
  image: rust:1-bookworm
  script:
    - apt-get update -qq && apt-get install -y -qq curl
    - curl -fsSL https://getassay.dev/install.sh | sh
    - assay ci --config ci-eval.yaml --trace-file traces/ci.jsonl --sarif .assay/reports/sarif.json --junit .assay/reports/junit.xml
  artifacts:
    when: always
    paths:
      - .assay/reports/
"#;

pub const GITIGNORE: &str = "/.eval/\n/out/\n*.db\n*.db-shm\n*.db-wal\n/assay\n";

pub const EVAL_CONFIG_DEFAULT_YAML: &str = r#"configVersion: 1
suite: "starter"
model: "trace"
tests:
  - id: "starter_regex"
    input:
      prompt: "replace_with_real_prompt"
    expected:
      type: regex_match
      pattern: ".*"
      flags: ["s"]
"#;

#[cfg(test)]
mod gitlab_tests {
    use super::GITLAB_CI_YML;

    const INIT_CI_SOURCE: &str = include_str!("cli/commands/init_ci.rs");

    #[test]
    fn gitlab_template_uses_the_owned_fail_closed_installer_once() {
        const INSTALL: &str = "curl -fsSL https://getassay.dev/install.sh | sh";

        assert_eq!(GITLAB_CI_YML.matches(INSTALL).count(), 1);
        assert!(!GITLAB_CI_YML.contains("https://assay.dev/install.sh"));
        assert!(!GITLAB_CI_YML.contains("curl -sSL"));
    }

    #[test]
    fn init_ci_reuses_the_gitlab_template_instead_of_copying_it() {
        assert!(INIT_CI_SOURCE
            .contains("\"gitlab\" => (crate::templates::GITLAB_CI_YML, \".gitlab-ci.yml\"),"));
        assert_eq!(
            INIT_CI_SOURCE
                .matches("crate::templates::GITLAB_CI_YML")
                .count(),
            1
        );
        assert!(!INIT_CI_SOURCE.contains("getassay.dev/install.sh"));
        assert!(!INIT_CI_SOURCE.contains("assay.dev/install.sh"));
        assert!(!INIT_CI_SOURCE.contains("curl -"));
    }
}