scc-cli 0.2.10

System Context Compiler CLI, daemon, MCP server, and Claude Code plugin
Documentation
//! Go extractor end-to-end tests (Wave 7 ยง46): indexing a small Go service
//! must surface the main entrypoint in flows/atlas, symbols in the System IR
//! export, and the store write symbol in a task pack for a "store" goal.

mod common;
use common::*;

// trace:v1 id=test.crates-scc-cli-tests-go.go-service work=WORK-wave-15-2-heterogeneous-hierarchy-edges-semantic-scoring-explain-rank-caching
fn go_service() -> tempfile::TempDir {
    let repo = copy_fixture("go-service");
    run_ok(&workdir(repo.path()), &["index", "--quiet"]);
    repo
}

#[test]
// trace:v1 id=test.crates-scc-cli-tests-go.go-index-flows-mention-main work=WORK-wave-15-2-heterogeneous-hierarchy-edges-semantic-scoring-explain-rank-caching
fn go_index_flows_mention_main() {
    let repo = go_service();
    let flows = run_ok(&workdir(repo.path()), &["flows"]);
    assert!(flows.contains("main"), "flows must mention main: {flows}");
}

#[test]
// trace:v1 id=test.crates-scc-cli-tests-go.go-atlas-has-service-component-and-main-entrypoint work=WORK-wave-15-2-heterogeneous-hierarchy-edges-semantic-scoring-explain-rank-caching
fn go_atlas_has_service_component_and_main_entrypoint() {
    let repo = go_service();
    let atlas = run_ok(&workdir(repo.path()), &["atlas"]);
    assert!(atlas.contains("ENTRYPOINTS"), "entrypoints section: {atlas}");
    assert!(atlas.contains("main"), "main entrypoint missing: {atlas}");
    // the service lives under internal/, which compiles to the "internal"
    // component (implementation listed as its path)
    assert!(atlas.contains("INTERNAL"), "service component missing: {atlas}");
    assert!(
        atlas.contains("Implementation: internal"),
        "service component implementation missing: {atlas}"
    );
}

#[test]
// trace:v1 id=test.crates-scc-cli-tests-go.go-export-has-symbols-from-main-go work=WORK-wave-15-2-heterogeneous-hierarchy-edges-semantic-scoring-explain-rank-caching
fn go_export_has_symbols_from_main_go() {
    let repo = go_service();
    let out = run_ok(&workdir(repo.path()), &["export", "system-ir.json"]);
    let ir: serde_json::Value = serde_json::from_str(&out).unwrap();
    let entities = ir["entities"].as_array().unwrap();
    let main_go_symbols: Vec<&str> = entities
        .iter()
        .filter(|e| e["kind"].as_str() == Some("symbol"))
        .filter(|e| e["attributes"]["file"].as_str() == Some("main.go"))
        .filter_map(|e| e["name"].as_str())
        .collect();
    assert!(
        main_go_symbols.contains(&"main"),
        "main.go symbols missing main: {main_go_symbols:?}"
    );
    // the service package's symbols are exported too (file=internal/service.go)
    let all_symbols: Vec<&str> = entities
        .iter()
        .filter(|e| e["kind"].as_str() == Some("symbol"))
        .filter_map(|e| e["name"].as_str())
        .collect();
    assert!(
        all_symbols.contains(&"NewStore") && all_symbols.contains(&"Store.Save"),
        "service symbols missing: {all_symbols:?}"
    );
}

#[test]
// trace:v1 id=test.crates-scc-cli-tests-go.go-task-pack-store-mentions-write-symbol work=WORK-wave-15-2-heterogeneous-hierarchy-edges-semantic-scoring-explain-rank-caching
fn go_task_pack_store_mentions_write_symbol() {
    let repo = go_service();
    let out = run_ok(
        &workdir(repo.path()),
        &["context", "task", "store", "--json"],
    );
    // The artifact is {pack, delta, delta_ids}; the assertions score the PACK.
    let artifact: serde_json::Value = serde_json::from_str(&out).unwrap();
    let pack = &artifact["pack"];
    let content = pack["content"].as_str().unwrap();
    assert!(
        content.contains("Store.Save"),
        "store write symbol missing from pack: {content}"
    );
    let ids: Vec<&str> = pack["entity_ids"]
        .as_array()
        .unwrap()
        .iter()
        .filter_map(|v| v.as_str())
        .collect();
    assert!(
        ids.iter().any(|id| id.contains("Store.Save")),
        "store write symbol missing from entity ids: {ids:?}"
    );
}