Commit 8830dae
authored
[test] Add tests for difc package: getItems, AddIntegrityTags, Intersect, checkFlowHelper (#1860)
## Test Coverage Improvement: `internal/difc` package
### Summary
Comprehensive test coverage improvement for the `internal/difc` package,
focusing on `getItems` as the primary target (most complex function with
lowest coverage) plus several closely related under-tested functions.
| Metric | Before | After |
|--------|--------|-------|
| Package coverage | 93.8% | **99.7%** |
| `getItems` | 58.3% | 95.8% |
| `AddIntegrityTags` | 0.0% | 100.0% |
| `Intersect` | 66.7% | 100.0% |
| `checkFlowHelper` | 90.9% | 100.0% |
| `resolve` | 88.5% | 100.0% |
| `Overall` | 80.0% | 100.0% |
| `GetItems` | 66.7% | 100.0% |
| `ToCollectionLabeledData` | 66.7% | 100.0% |
| `extractIndexFromPath` | 89.5% | 100.0% |
| `pathEntryToResource` | 87.5% | 100.0% |
| `ParsePathLabels` | 83.3% | 100.0% |
| `NewPathLabeledData` | 83.3% | 100.0% |
### Why `getItems`?
`getItems` (`internal/difc/path_labels.go:192`) was selected as the
primary target:
- **Lowest coverage** among complex functions at 58.3%
- **Highest complexity**: JSON pointer navigation with 6+ distinct
branches (map traversal, array index traversal, out-of-bounds errors,
non-numeric index errors, unexpected type errors, final non-array error)
- **Core DIFC logic**: used by `resolve()` which drives the entire
path-label system
### Tests Added
#### New file: `internal/difc/path_labels_coverage_test.go` (28 test
functions)
Covers all missing branches in `getItems`:
- ✅ Path segment not found in map → error
- ✅ Final path navigates to non-array value → error
- ✅ Array index navigation through `[]interface{}` → success
- ✅ Array index out of bounds → error
- ✅ Non-numeric array index → error
- ✅ Unexpected type at path segment (default case) → error
- ✅ Empty path segment (consecutive slashes) → continue/skip
Covers lazy-resolve branches:
- ✅ `Overall()` called before `GetItems()` — lazy resolve
- ✅ `GetItems()` called on unresolved data — lazy resolve
- ✅ `ToCollectionLabeledData()` on unresolved data — lazy resolve
Covers other gaps:
- ✅ `resolve()` early return when already resolved (direct call)
- ✅ `resolve()` skips labeled paths that don't match items_path
- ✅ `pathEntryToResource(nil)` → "unlabeled" resource
- ✅ `ParsePathLabels` with invalid JSON → error
- ✅ `NewPathLabeledData` resolve-error propagation
- ✅ `extractIndexFromPath` third HasPrefix branch (no slash separator)
- ✅ `extractIndexFromPath` empty remainder → "no index" error
- ✅ `unwrapMCPResponse` when content[0] is not a map
- ✅ MCP-wrapped single-item response
- ✅ `Overall()` with empty items collection
- ✅ `Overall()` union semantics across multiple items
- ✅ `ToResult()` preserves original MCP-wrapped data
#### Additions to `internal/difc/agent_test.go`
- ✅ `AddIntegrityTags` — was at 0% coverage; now 100%
- Empty slice, nil slice, non-empty slice, duplicates, independence from
secrecy
#### Additions to `internal/difc/labels_test.go`
- ✅ `Intersect` — covers the non-nil intersection path with tag removal
- ✅ `checkFlowHelper` nil-source + non-empty-target + integrity mode
(lines 213-215 previously untested)
### Coverage Report
```
Before: 93.8% coverage (internal/difc package)
After: 99.7% coverage (internal/difc package)
Improvement: +5.9%
```
Remaining gap (0.3%): `GetOrCreate.double-check-after-write-lock` — the
concurrent double-check-locking pattern that requires precise goroutine
race timing to cover deterministically. This is intentional defensive
code and the existing 100-goroutine concurrent test provides sufficient
confidence.
### Test Execution
All 3 modified/new test files compile and pass cleanly. Tests follow the
project's conventions:
- Table-driven tests where applicable
- `require` for critical assertions (stop on failure)
- `assert` for non-critical assertions (continue on failure)
- Bound asserters where multiple assertions exist
- Descriptive test names using the `TestFunctionName_Scenario` pattern
---
*Generated by Test Coverage Improver*
*Previous run: `internal/guard.parseLabelAgentResponse` (2026-03-12,
43.3% → 100%)*
*This run: `internal/difc.getItems` + difc package (2026-03-13, 93.8% →
99.7%)*
> Generated by [Test Coverage
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/23060669571)
·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-coverage-improver%22&type=pullrequests)
> [!WARNING]
> <details>
> <summary>File tree
4 files changed
+705
-2
lines changed- internal/difc
4 files changed
+705
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
258 | 256 | | |
259 | 257 | | |
260 | 258 | | |
| |||
0 commit comments