Files
CASAN/AINative_OKR_CASAN5/packages/casan-harness/tests/phase2-sourcegen-tests.sh
T
thanhnvandClaude Opus 4.8 664bd1f00c feat(plan-01): Phase 1 — relocate harness code to packages/casan-harness (symlink facade)
Physically move the pure-code subtrees out of .specify into the package, leaving
compat symlinks at the old .specify/<dir> paths so every existing reference (internal
CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put.

Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/
  .specify/<dir>  ->  packages/casan-harness/<dir>   (+ .specify/<dir> symlink)
Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/
  init-options.json traceability-map.json

Python `.resolve()` self-location followed the compat symlink into packages and lost
the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and
dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed
parent depth (fixes "missing trace files" in run-casan4).

Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs
close to the 600s default and can tip over under load; this is timing variance, not a
regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 00:06:00 +09:00

99 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
PASS=0; FAIL=0
pass(){ echo "PASS: $1"; PASS=$((PASS+1)); }
fail(){ echo "FAIL: $1"; FAIL=$((FAIL+1)); }
mkdir -p "$WORK/scripts" "$WORK/.specify/scripts/bash" "$WORK/docs/input"
cp "$PROJECT_ROOT/scripts/casan-step.mjs" "$WORK/scripts/casan-step.mjs"
cat > "$WORK/docs/input/okr-requirement.md" <<'EOF'
# OKR Requirement
- FR-01 Login
- FR-02 Create Objective
- FR-03 Create Key Result
- FR-04 Update Progress
- FR-05 Dashboard
- SCR-00 Login
- SCR-01 Dashboard
- SCR-02 Detail
- SCR-03 Create Objective
- SCR-04 Key Result Detail
EOF
cat > "$WORK/docs/technical_architecture.md" <<'EOF'
# Architecture
Frontend uses API client. Backend uses NestJS and Prisma.
EOF
cat > "$WORK/.specify/scripts/bash/model-router.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
prompt_file="$1"
out_json="$2"
if grep -q "Business Design" "$prompt_file"; then
cat > "$out_json" <<'JSON'
{"text":"# Model Generated BD\n\n## Screen Layout\n- SCR-00 Login\n- SCR-01 Dashboard\n- SCR-02 Detail\n- SCR-03 Create Objective\n- SCR-04 Key Result Detail\n\n## API Boundary\nFrontend calls backend through src/lib/api.ts.\n","input_tokens":21,"output_tokens":34,"total_tokens":55}
JSON
else
cat > "$out_json" <<'JSON'
{"text":"# Model Generated SRS\n\n## Functional Requirements\n- FR-01 Login\n- FR-02 Create Objective\n- FR-03 Create Key Result\n- FR-04 Update Progress\n- FR-05 Dashboard\n\n## Non Functional Requirements\nAuthentication required.\n","input_tokens":20,"output_tokens":30,"total_tokens":50}
JSON
fi
EOF
chmod +x "$WORK/.specify/scripts/bash/model-router.sh"
cat > "$WORK/.specify/scripts/bash/artifact-scan.sh" <<'EOF'
#!/usr/bin/env bash
exit 0
EOF
chmod +x "$WORK/.specify/scripts/bash/artifact-scan.sh"
(
cd "$WORK" || exit 1
CASAN_OUTPUT="$WORK/out-template.md" node scripts/casan-step.mjs 01-srs 1 >/dev/null
)
if grep -q "FR-05 Dashboard" "$WORK/docs/output/ipa-docs/srs/srs-mod01-okr-management.md" \
&& grep -q "source=template" "$WORK/docs/output/output_logs/001-okr-web-app/reports/01-srs-report.md"; then
pass "source-gen default mode keeps deterministic template"
else
fail "default template generation changed"
fi
(
cd "$WORK" || exit 1
CASAN_GEN_MODE=model CASAN_OUTPUT="$WORK/out-model.md" node scripts/casan-step.mjs 02-bd 1 >/dev/null
)
if grep -q "Model Generated BD" "$WORK/docs/output/ipa-docs/bd/bd-mod01-okr-management.md" \
&& grep -q "source=model" "$WORK/docs/output/output_logs/001-okr-web-app/reports/02-bd-report.md"; then
pass "source-gen model mode accepts scanned valid model output"
else
fail "model generated BD was not accepted"
fi
cat > "$WORK/.specify/scripts/bash/artifact-scan.sh" <<'EOF'
#!/usr/bin/env bash
exit 2
EOF
chmod +x "$WORK/.specify/scripts/bash/artifact-scan.sh"
(
cd "$WORK" || exit 1
CASAN_GEN_MODE=model CASAN_OUTPUT="$WORK/out-fallback.md" node scripts/casan-step.mjs 01-srs 1 >/dev/null
)
if grep -q "Functional requirements extracted" "$WORK/docs/output/ipa-docs/srs/srs-mod01-okr-management.md" \
&& grep -q "source=template-fallback" "$WORK/docs/output/output_logs/001-okr-web-app/reports/01-srs-report.md"; then
pass "source-gen falls back to template when H4 artifact scan blocks model output"
else
fail "source-gen did not fallback after artifact scan block"
fi
echo ""
echo "===== SOURCEGEN TESTS: PASS=$PASS FAIL=$FAIL ====="
[[ "$FAIL" -eq 0 ]] || exit 1