# Step 11: Source Target Resolver

## 담당 역할과 필수 스킬

- 담당 역할: `implementation-agent`
- 필수 스킬: `harness`, `fesa-cpp-msvc-tdd`
- 이 Step만 `RED -> observed failure -> minimal GREEN -> focused/full VERIFY`로 수행한다.

## 읽어야 할 파일

- `/AGENTS.md`
- `/docs/CODINGSTYLE.md`
- `/docs/ARCHITECTURE.md`
- `/docs/ADR.md`
- `/docs/linear-static-3d-euler-beam/io.md`
- `/docs/linear-static-mitc4-shell/io.md`
- `/docs/cpp-object-oriented-modular-refactoring/implementation-plan.md`
- `/include/fesa/core/source_identity.h`
- `/include/fesa/model/domain.h`, `/src/fesa/model/domain.cpp`
- `/src/fesa/io/abaqus/domain_mapper.cpp`
- `/src/fesa/fem/dof_manager.cpp`
- `/src/fesa/assembly/load_assembler.cpp`
- `/src/fesa/results/result_recovery.cpp`
- matching mapper/DOF/load/recovery tests
- `/src/fesa/CMakeLists.txt`, `/tests/CMakeLists.txt`
- `/phases/cpp-object-oriented-modular-refactoring/index.json`
- `/phases/cpp-object-oriented-modular-refactoring/step11.md`

## 작업

Requirement `R-DUP-002`의 ASCII/source-target owner를 구현한다.

1. `/tests/unit/core/ascii_test.cpp`와
   `/tests/unit/model/source_target_resolver_test.cpp`를 먼저 추가한다.
2. `C-DUP-004` tests cover ASCII-only lower/equality, positive source-label parsing,
   separate node/element set namespaces, instance identity, declaration-order expansion,
   duplicate/missing/ambiguous/nonpositive rejection and deterministic diagnostic order.
3. Missing headers/symbols로 RED compile failure를 기록한다.
4. Create `/include/fesa/core/ascii.h`, `/src/fesa/core/ascii.cpp`,
   `/include/fesa/model/source_target_resolver.h`, and
   `/src/fesa/model/source_target_resolver.cpp`; register both sources and both tests in CMake.
5. Candidate core functions:

```cpp
char AsciiLower(char value) noexcept;
bool AsciiCaseInsensitiveEquals(std::string_view lhs,
                                std::string_view rhs) noexcept;
Result<std::int64_t> ParsePositiveSourceLabel(std::string_view text);
```

6. Candidate model interface:

```cpp
enum class SourceEntityKind { kNode, kElement };

struct SourceTargetIndexEntry {
  SourceEntityKind entity_kind;
  std::string instance_name;
  std::string target_name;
  SourceEntityId source_id;
  EntityIndex entity_index;
  std::size_t declaration_order;
};

class SourceTargetIndex {
 public:
  explicit SourceTargetIndex(std::vector<SourceTargetIndexEntry> entries);
  const std::vector<SourceTargetIndexEntry>& Entries() const noexcept;
};

struct SourceTargetQuery {
  SourceEntityKind entity_kind;
  std::string instance_name;
  std::string target_name_or_label;
};

struct ResolvedSourceTarget {
  SourceEntityId source_id;
  EntityIndex entity_index;
};

class SourceTargetResolver {
 public:
  explicit SourceTargetResolver(const SourceTargetIndex& index) noexcept;
  Result<std::vector<ResolvedSourceTarget>> Resolve(
      const SourceTargetQuery& query) const;
};
```

7. `SourceTargetIndex` is an immutable index built from validated candidate or Domain semantic
   records. It owns its compact entries; the resolver stores a non-owning reference, so the index
   lifetime must outlive the resolver and Doxygen must state it.
8. Replace repeated `AsciiLower`, equal-name, positive-integer, and same-meaning source resolution
   helpers only. Preserve each owner-specific diagnostic category/source location.

## Acceptance Criteria

```powershell
cmake --build .harness/build --config Debug --target fesa_unit_tests
ctest --test-dir .harness/build -C Debug `
  -R "Ascii|SourceTargetResolver|InpDomainMapping|DofManager|LoadAssembly|ResultRecovery" `
  --output-on-failure
rg -n "AsciiLower|EqualName|TryPositiveInteger" src/fesa
& "C:/Program Files/LLVM/bin/clang-format.exe" --dry-run --Werror `
  include/fesa/core/ascii.h src/fesa/core/ascii.cpp `
  include/fesa/model/source_target_resolver.h `
  src/fesa/model/source_target_resolver.cpp `
  tests/unit/core/ascii_test.cpp `
  tests/unit/model/source_target_resolver_test.cpp
cmake --build .harness/build --config Debug
ctest --test-dir .harness/build -C Debug --show-only=json-v1
ctest --test-dir .harness/build -C Debug --output-on-failure
```

The helper scan may show only the shared definitions and intentional calls, not repeated local
definitions. Full diagnostics and stable order tests must pass.

## 검증 및 상태 갱신

- RED, focused resolution cases, duplicate scan and full CTest를 summary에 기록한다.
- Identity/diagnostic order regression이면 `error`; missing upstream identity contract이면
  `blocked`로 기록한다.
- 성공 시 현재 Step만 `completed`로 갱신한다.
- timestamp, retry, commit, advancement는 Executor 소유다.

## 금지사항

- Unicode case folding이나 locale behavior를 추가하지 마라. 이유: input contract is ASCII.
- Node와 element set namespace를 합치지 마라.
- Domain mapper를 responsibility files로 split하지 마라. 이유: Step 21 소유다.
- 직접 commit하거나 hook script를 수동 실행하지 마라.
