# shellcheck shell=bash

# 이 lib 은 단독으로 source 될 수 있다(계약 테스트가 그렇게 부른다). checks
# 경로 계산은 common.sh 한 곳에만 두고, 없으면 여기서 채운다.
# shellcheck source=common.sh
[ -n "${OKSTRA_VALIDATOR_CHECKS:-}" ] || . "$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"

write_validation_brief() {
  local brief_path="$1"
  local brief_title="$2"
  local task_group="$3"
  local task_id="$4"
  local validation_focus="$5"
  local task_key_value=""

  task_key_value="$(task_key "$task_group" "$task_id")"

  cat >"$brief_path" <<EOF
# Cross Verify Task Brief

## Brief Identity

- Brief Title: $brief_title
- Project ID: \`okstra-validation\`
- Task Group: \`$task_group\`
- Task ID: \`$task_id\`
- Task Key: \`$task_key_value\`
- Related Tasks:
- Task Type: \`$TASK_TYPE\`
- Requested Outcome: validate asset seeding, refresh behavior, and discovery catalog integrity
- Owner: \`Oz\`

## Problem or Request Summary

- Verify that okstra seeds all Claude Markdown assets into the target project on first run.
- Verify that refresh is optional and only forced with the refresh option.
- Verify that config and deployment expected states are discoverable by task bundle artifacts.
- Validation focus: $validation_focus

## Source Materials

- Primary problem statement: \`validation\`
- Existing analysis or notes:
- Related raw samples or logs:
- Related code paths: \`scripts/okstra.sh\`
- Related tickets or docs: \`OKSTRA_USAGE_MANUAL.md\`
- Previous reports in the same task history:

## Constraints and Assumptions

- Known constraints: validation must stay inside the temporary project root
- Known assumptions: task bundle artifacts are the canonical source for skill loading
- Things that are still uncertain: none

## Configuration References and Expected Values

- Config file: \`.claude/settings.json\`
  - Expected values:
    - installed okstra Claude assets must remain discoverable under \`~/.claude/skills/\` and \`~/.claude/agents/\` (managed by \`okstra install\`)
- Config file: \`.okstra/discovery/latest-task.json\`
  - Expected values:
    - latest prepared task pointer must include the current task key
    - task catalog path must be present
- Config file: \`.okstra/discovery/task-catalog.json\`
  - Expected values:
    - task catalog must preserve prepared task bundles by task key
    - task catalog must allow task-group and task-id level distinction

## Deployment Manifests and Expected Values

- Manifest file: \`deploy/values.yaml\`
  - Expected values:
    - image tag should match the validated release candidate for this task
    - rollout-specific values must be verified against the task brief before final approval
- Manifest file: \`k8s/deployment.yaml\`
  - Expected values:
    - env and image settings must match the task brief requirements
    - missing deployment expectations must be reported as missing information

## Questions for Workers

1. Are all required Claude assets seeded into the temporary target project?
2. Do the generated task artifacts preserve config and deployment expected states?
3. Does refresh remain optional rather than automatic?
4. Does the discovery catalog preserve distinct task entries?

## Expected Outputs

- Asset seed verification:
- Missing information:
- Risks:
- Recommended next actions:
EOF
}

write_worker_prompt_history_fixture() {
  local task_group="$1"
  local task_id="$2"
  local worker_id="$3"
  local expected_task_manifest_relative_path=""

  expected_task_manifest_relative_path="$(task_manifest_relative_path "$task_group" "$task_id")"

  python3 "$OKSTRA_VALIDATOR_CHECKS/fixtures-01.py" "$PROJECT_ROOT" "$expected_task_manifest_relative_path" "$worker_id"
}

prepare_run_validator_fixture() {
  local task_group="$1"
  local task_id="$2"
  local omitted_worker_id="$3"
  local expected_task_manifest_relative_path=""

  expected_task_manifest_relative_path="$(task_manifest_relative_path "$task_group" "$task_id")"

  python3 "$OKSTRA_VALIDATOR_CHECKS/fixtures-02.py" "$PROJECT_ROOT" "$expected_task_manifest_relative_path" "$omitted_worker_id"
}
