Skip to content

Commit fc792bb

Browse files
bschellenberger2600cursoragentBen Schellenberger
authored
add blocked-string rewrite validation fixtures (#8)
## Summary - add reusable sanitize/rewrite fixtures that seed blocked strings across file contents, commit messages, refs, and paths - add scan/assert helpers for full-surface detection and removal checks - document fixture usage and focused test commands in README/developer docs ## Test plan - [x] `go test ./... -run 'RewriteValidation|BlockedStringCoverage'` - [x] `go test ./...` Made with [Cursor](https://cursor.com) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Adds new exported helpers that execute git commands and parse repo history/refs, so edge cases and performance of scans could affect downstream tests; changes are otherwise additive and well-covered by new tests. > > **Overview** > Adds a new sanitize/rewrite validation fixture (`CreateRewriteValidationFixture`) that seeds a repo with a configurable blocked token across **file content, commit messages, refs (branch/tag), and object paths**. > > Introduces scan/validate/assert helpers (`ScanBlockedStringSurfaces*`, `ValidateBlockedStringCoverage*`, `AssertBlockedStringCoverage*`) to verify blocked-string detection coverage pre-rewrite and confirm complete removal post-rewrite. > > Updates `README.md`, `DEVELOPER_GUIDE.md`, and package docs with usage examples and a focused test command, and adds `sanitize_fixtures_test.go` to exercise fixture creation, invalid token rejection, and a simulated history rewrite cleanup flow. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dc8e18b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated developer guide with sanitize/rewrite testing workflow examples and targeted test commands * Added sanitize/rewrite validation helpers to README with usage guidance * **New Features** * Added test fixture creation helper for seeding blocked-strings across Git surfaces (contents, history, refs, paths) * Added blocked-string detection and assertion utilities for validation testing * **Tests** * Added comprehensive test coverage for sanitize/rewrite validation scenarios <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Ben Schellenberger <TBRX103@users.noreply.github.com> Co-authored-by: Ben Schellenberger <bschellenberger2600@users.noreply.github.com>
1 parent ad81ae5 commit fc792bb

5 files changed

Lines changed: 633 additions & 0 deletions

File tree

DEVELOPER_GUIDE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ go test ./...
3131
## Project structure
3232

3333
- `fixtures.go`: base repo creation and command helpers.
34+
- `sanitize_fixtures.go`: reusable sanitize/rewrite fixtures plus blocked-string scan/assert helpers.
3435
- `scenarios.go`: fluent scenario builder and predefined multi-repo scenarios.
3536
- `snapshots.go`: snapshot/restore utilities for expensive test setup reuse.
3637
- `fixtures_test.go`: external package tests (`testutil_test`) that validate public API usage.
38+
- `sanitize_fixtures_test.go`: coverage tests for blocked-string detection/removal across content/history/refs/paths.
3739
- `usb_fixtures.go` / `usb_fixtures_test.go`: USB volume root and `.git-fire` config helpers for backup-mode style tests.
3840
- `scenarios_test.go`: package-internal tests for scenario/snapshot behavior.
3941

@@ -74,6 +76,18 @@ Common usage split:
7476
- `CreateTestRepo`: fast setup for single-repo state.
7577
- `NewScenario`: multi-repo topologies and fluent setup.
7678
- `SnapshotRepo`/`RestoreSnapshot`: performance optimization for repeated expensive setups.
79+
- `CreateRewriteValidationFixture` + blocked-string assertions: sanitize/rewrite validation against file contents, commit messages, refs, and paths.
80+
81+
Sanitize/rewrite focused validation loop:
82+
83+
```bash
84+
# Run only sanitize/rewrite fixture and assertion tests.
85+
go test ./... -run 'RewriteValidation|BlockedStringCoverage'
86+
87+
# Full required local gate.
88+
go vet ./...
89+
go test ./...
90+
```
7791

7892
## Adding new helpers
7993

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go get github.com/git-fire/git-testkit
3030
- Repository fixtures (`CreateTestRepo`, `CreateBareRemote`, `RunGitCmd`)
3131
- Scenario builders for common multi-repo states (`NewScenario`, conflict/worktree helpers)
3232
- Snapshot helpers for capturing and restoring repository state in tests
33+
- Sanitize/rewrite validation helpers for blocked-string coverage across content/history/refs/paths
3334

3435
## API overview
3536

@@ -38,6 +39,8 @@ go get github.com/git-fire/git-testkit
3839
- `NewScenario(t)` returns a fluent builder for multi-repo test topologies.
3940
- `SnapshotRepo(t, path)` and `RestoreSnapshot(t, snap)` speed up repeated fixture setup.
4041
- `IsDirty`, `GetCurrentSHA`, `GetBranches`, `GetRemotes` provide common assertions/helpers.
42+
- `CreateRewriteValidationFixture(t, opts)` seeds blocked strings across file contents, commit messages, refs, and paths.
43+
- `AssertBlockedStringCoverageDetected` and `AssertBlockedStringCoverageRemoved` validate sanitize/rewrite coverage before/after rewriting.
4144

4245
## Quickstart for using in tests
4346

@@ -113,6 +116,33 @@ func TestUsingSnapshot(t *testing.T) {
113116
}
114117
```
115118

119+
### Validate sanitize/rewrite coverage
120+
121+
```go
122+
func TestRewriteRemovesBlockedString(t *testing.T) {
123+
fixture := testutil.CreateRewriteValidationFixture(t, testutil.RewriteValidationFixtureOptions{
124+
Name: "rewrite-fixture",
125+
BlockedString: "blockedtoken",
126+
})
127+
128+
// Confirm fixture coverage before running your rewrite logic.
129+
testutil.AssertBlockedStringCoverageDetected(t, fixture.RepoPath, fixture.BlockedString)
130+
131+
// Run your sanitizer/rewrite command against fixture.RepoPath here.
132+
// Example:
133+
// testutil.RunGitCmd(t, fixture.RepoPath, "filter-branch", ...)
134+
135+
// Validate the blocked string is removed from all tracked surfaces.
136+
testutil.AssertBlockedStringCoverageRemoved(t, fixture.RepoPath, fixture.BlockedString)
137+
}
138+
```
139+
140+
Run just sanitize/rewrite-focused tests:
141+
142+
```bash
143+
go test ./... -run 'RewriteValidation|BlockedStringCoverage'
144+
```
145+
116146
## Notes
117147

118148
- Snapshots are intended for deterministic test fixtures and only restore regular files/directories.

doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// remote, diverged clones, worktrees, conflict states).
1212
// - [SnapshotRepo] / [RestoreSnapshot] for capturing expensive fixture state
1313
// once and restoring it cheaply across subtests.
14+
// - [CreateRewriteValidationFixture] plus blocked-string assertions for
15+
// sanitize/rewrite validation across content, commit history, refs, and paths.
1416
//
1517
// All helpers integrate with Go's testing.T: repositories are created inside
1618
// t.TempDir() and cleaned up automatically, and setup failures call t.Fatalf

0 commit comments

Comments
 (0)