Skip to content

Commit 29edb90

Browse files
committed
Document macro maintenance workflow
1 parent efa3993 commit 29edb90

2 files changed

Lines changed: 123 additions & 245 deletions

File tree

AGENTS.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Most changes are correctness-sensitive because public behavior is generated by m
6767
## Testing Expectations
6868

6969
- Run `swift test` before finishing any behavioral change.
70+
- Preserve the macro guardrail suite in `Tests/ObservableDefaultsMacroTests`. It exists to catch generated-code regressions before runtime tests do.
71+
- When changing macro generation, run `swift test --filter ObservableDefaultsMacroTests` in addition to any affected runtime suites.
72+
- Keep macro coverage split by responsibility:
73+
- `MacroExpansionSnapshotTests.swift` for expanded-source and formatted-source snapshots
74+
- `MacroStructureTests.swift` for syntax/shape assertions that should survive harmless formatting changes
75+
- `MacroDiagnosticTests.swift` for diagnostics and invalid-argument coverage
76+
- Add or update fixtures in `Tests/ObservableDefaultsMacroTests/Fixtures` when a macro change introduces a new meaningful expansion scenario.
77+
- Update files under `Tests/ObservableDefaultsMacroTests/__Snapshots__` only when the expanded output intentionally changes. Treat snapshot diffs as generated-code behavior changes unless proven otherwise.
7078
- If a change touches external notifications, fallback logic, or equality checks, at minimum run:
7179
- `swift test --filter ExternalChangeEqualityTests`
7280
- `swift test --filter ObservableDefaultsTests`
@@ -77,16 +85,31 @@ Most changes are correctness-sensitive because public behavior is generated by m
7785
- `swift test --filter PrefixTests`
7886
- `swift test --filter WhitespaceTests`
7987
- `swift test --filter StringParameterTests`
88+
- If a change touches macro parameter parsing or diagnostics, also run:
89+
- `swift test --filter ObservableDefaultsMacroTests`
8090
- If a change touches storage format or overload resolution, run:
8191
- `swift test --filter RawRepresentableCodableTests`
8292
- `swift test --filter Issue26OverloadAmbiguityTests`
93+
- If a change touches observer lifetime, notification registration, or external notification teardown, also run:
94+
- `swift test --filter ObservableDefaultsTests`
95+
- `swift test --filter ObservableCloudTests`
96+
- verify the runtime regression tests covering model deallocation and post-release notifications still pass
8397

8498
### Test Isolation Rules
8599

86100
- `UserDefaults` tests should use isolated suite names. Prefer `UserDefaults.getTestInstance(suiteName:)`, and use a unique suite per test when cross-test interference is possible.
87101
- Cloud `.testMode` tests use per-test mock suite isolation through `NSUbiquitousKeyValueStoreWrapper.testSuiteName`. Preserve that mechanism.
88102
- If a suite relies on shared notifications or shared storage state, make it `.serialized`.
89103
- Do not “fix” flaky tests by weakening expectations if the real issue is shared storage or notification interference.
104+
- Prefer running `swift test` commands serially when changing macro/plugin code. Parallel SwiftPM test runs can contend on `.build` and produce misleading cache or lock failures.
105+
106+
### Macro Test Workflow
107+
108+
- Use `swift-testing` by default for new repository tests. Keep `XCTest` only where macro-testing APIs still require it.
109+
- Prefer structure assertions plus snapshots over snapshots alone. Snapshot tests catch whole-output drift; structure tests catch semantic shape changes with less formatting sensitivity.
110+
- Snapshot files are intentionally not reformatted by the pre-commit hook. Do not manually reformat files under `Tests/ObservableDefaultsMacroTests/__Snapshots__`.
111+
- Macro string parameters are valid only when they are plain string literals composed entirely of `StringSegmentSyntax` segments. Interpolated strings must be diagnosed, not partially accepted.
112+
- Macro boolean parameters must diagnose invalid non-literal expressions rather than silently falling back to defaults.
90113

91114
## Documentation Rules
92115

@@ -105,8 +128,9 @@ When reviewing changes, prioritize:
105128
2. missing tests for external changes and fallback paths
106129
3. `MainActor` and `defaultIsolationIsMainActor` coverage
107130
4. `observeFirst` correctness
108-
5. storage format compatibility for RawRepresentable/Codable hybrids
109-
6. test isolation and notification scope
131+
5. observer lifecycle and notification token teardown
132+
6. storage format compatibility for RawRepresentable/Codable hybrids
133+
7. test isolation and notification scope
110134

111135
## Release Workflow
112136

0 commit comments

Comments
 (0)