Skip to content

Commit 4d57743

Browse files
committed
feat(smx509): add declarative test patch system
- Add scripts/smx509/gen_test_patches.go: generates test patches from Go stdlib test files (with package rename) vs smx509/ test files - Add scripts/smx509/test-patches/: - 010-testenv-stub.patch: new file internal_testenv.go (stdlib testenv stub) - 020-envvars-abs-path.patch: fix TestEnvVars SSL_CERT_FILE absolute paths - Extend sync.ps1 with test file sync: - -TestOnly switch for test-only sync mode - Auto-detect and copy *_test.go from stdlib - Copy testdata/ directory - Rename package x509 -> smx509 in test files - Apply test-patches/ after sync - Update smx509-upgrade Skill with test patch workflow
1 parent 19c8041 commit 4d57743

6 files changed

Lines changed: 455 additions & 57 deletions

File tree

.github/skills/smx509-upgrade/skill.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ scripts/smx509/
4141
│ ├── 020-pkcs-keys.patch
4242
│ ├── 030-sm4-pem.patch
4343
│ └── 100-extensions.patch
44-
└── test-patches/ # Test file patches (future)
45-
├── 001-package-rename.patch
46-
└── ...
44+
├── test-patches/ # Declarative test patches (2 files)
45+
│ ├── 010-testenv-stub.patch
46+
│ └── 020-envvars-abs-path.patch
47+
└── gen_test_patches.go # Regenerates test patches from stdlib↔smx509 diff
4748
```
4849

4950
**Patch numbering convention:**
@@ -153,24 +154,35 @@ When resolving conflicts, these MUST be preserved:
153154

154155
### Step 6: Sync Test Files
155156

156-
Test files are maintained independently from source patches. On Go upgrade:
157+
Test files are synced automatically by `sync.ps1` (test file sync section). The script:
158+
1. Copies `*_test.go` from stdlib `crypto/x509/` to `smx509/`
159+
2. Copies `testdata/` from stdlib to `smx509/testdata/`
160+
3. Renames `package x509``package smx509` in all test files
161+
4. Applies declarative test patches from `scripts/smx509/test-patches/`
157162

158-
1. **Copy new stdlib test files:**
159-
```bash
160-
cp $GOROOT/src/crypto/x509/*_test.go smx509/
161-
cp -r $GOROOT/src/crypto/x509/testdata/ smx509/testdata/
162-
```
163+
```bash
164+
# Test-only sync (source files unchanged):
165+
pwsh scripts/smx509/sync.ps1 -TestOnly
166+
167+
# Full sync (source + test):
168+
pwsh scripts/smx509/sync.ps1
169+
```
163170

164-
2. **Apply test patches** (from `scripts/smx509-test-patches/`):
165-
```bash
166-
pwsh scripts/smx509/sync.ps1 -TargetDir smx509 -PackageName smx509 -TestOnly
167-
# Or manually apply test patches
168-
```
171+
**Current test patches:**
172+
- `010-testenv-stub.patch`: new file `internal_testenv.go` (stub for `internal/testenv`)
173+
- `020-envvars-abs-path.patch`: fixes TestEnvVars `SSL_CERT_FILE` to use absolute paths
169174

170-
3. **Verify custom test fixes are preserved:**
171-
- `root_unix_test.go`: TestEnvVars uses absolute paths for SSL_CERT_FILE
172-
- `internal_testenv.go`: stub for `internal/testenv` replacement
173-
- Package name: all `*_test.go` must have `package smx509` (not `package x509`)
175+
After sync, verify custom test fixes are preserved:
176+
- `root_unix_test.go`: TestEnvVars uses `filepath.Join(tmpDir, testFile)` for SSL_CERT_FILE
177+
- `internal_testenv.go`: stub for `internal/testenv` replacement
178+
- Package name: all `*_test.go` must have `package smx509`
179+
180+
**If test patches need updating** (stdlib changed the affected code):
181+
```bash
182+
# Manually fix test files in smx509/
183+
# Then regenerate test patches:
184+
go run scripts/smx509/gen_test_patches.go
185+
```
174186

175187
### Step 7: Validate
176188

@@ -192,7 +204,11 @@ go test ./...
192204
### Step 8: Regenerate Patches
193205

194206
```bash
207+
# Source patches
195208
go run scripts/smx509/gen_patches.go
209+
210+
# Test patches
211+
go run scripts/smx509/gen_test_patches.go
196212
```
197213

198214
Verify all 5 patches are regenerated:
@@ -225,8 +241,9 @@ git push origin develop
225241
2. **Baseline is committed**`scripts/smx509/baseline/` is version-controlled, update it explicitly on Go upgrade
226242
3. **`sync.ps1` defaults to `smx509`**`-TargetDir` and `-PackageName` can be omitted for standard usage
227243
4. **PowerShell git ExitCode=1** — PowerShell treats git stderr as error; check actual output, not exit code
228-
5. **Test files NOT in patches**`*_test.go` changes are tracked separately, not in `patches/`
244+
5. **Test files NOT in source patches**`*_test.go` changes are in `test-patches/`, not in `patches/`
229245
6. **`internal/` imports** — any new `internal/*` or `crypto/internal/*` imports in stdlib must be added to `ImportRewriteMap` in `sync.ps1`
246+
7. **Test patches must be regenerated** — if stdlib changed `root_unix_test.go` or test files referencing `testenv`, run `gen_test_patches.go`
230247

231248
## Decision Checklist
232249

@@ -236,6 +253,7 @@ Before merging, verify:
236253
- [ ] `go test ./smx509/...` passes
237254
- [ ] `go test ./pkcs7/... ./cfca/... ./pkcs8/...` passes
238255
- [ ] `gen_patches.go` output matches committed patches (CI check)
256+
- [ ] `gen_test_patches.go` output matches committed test-patches
239257
- [ ] Test files have correct `package smx509`
240258
- [ ] Custom test fixes are re-applied
241259
- [ ] `ImportRewriteMap` updated if stdlib added new internal imports

.qoder/skills/smx509-upgrade/SKILL.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ scripts/smx509/
4141
│ ├── 020-pkcs-keys.patch
4242
│ ├── 030-sm4-pem.patch
4343
│ └── 100-extensions.patch
44-
└── test-patches/ # Test file patches (future)
45-
├── 001-package-rename.patch
46-
└── ...
44+
├── test-patches/ # Declarative test patches (2 files)
45+
│ ├── 010-testenv-stub.patch
46+
│ └── 020-envvars-abs-path.patch
47+
└── gen_test_patches.go # Regenerates test patches from stdlib↔smx509 diff
4748
```
4849

4950
**Patch numbering convention:**
@@ -153,24 +154,35 @@ When resolving conflicts, these MUST be preserved:
153154

154155
### Step 6: Sync Test Files
155156

156-
Test files are maintained independently from source patches. On Go upgrade:
157+
Test files are synced automatically by `sync.ps1` (test file sync section). The script:
158+
1. Copies `*_test.go` from stdlib `crypto/x509/` to `smx509/`
159+
2. Copies `testdata/` from stdlib to `smx509/testdata/`
160+
3. Renames `package x509``package smx509` in all test files
161+
4. Applies declarative test patches from `scripts/smx509/test-patches/`
157162

158-
1. **Copy new stdlib test files:**
159-
```bash
160-
cp $GOROOT/src/crypto/x509/*_test.go smx509/
161-
cp -r $GOROOT/src/crypto/x509/testdata/ smx509/testdata/
162-
```
163+
```bash
164+
# Test-only sync (source files unchanged):
165+
pwsh scripts/smx509/sync.ps1 -TestOnly
166+
167+
# Full sync (source + test):
168+
pwsh scripts/smx509/sync.ps1
169+
```
163170

164-
2. **Apply test patches** (from `scripts/smx509-test-patches/`):
165-
```bash
166-
pwsh scripts/smx509/sync.ps1 -TargetDir smx509 -PackageName smx509 -TestOnly
167-
# Or manually apply test patches
168-
```
171+
**Current test patches:**
172+
- `010-testenv-stub.patch`: new file `internal_testenv.go` (stub for `internal/testenv`)
173+
- `020-envvars-abs-path.patch`: fixes TestEnvVars `SSL_CERT_FILE` to use absolute paths
169174

170-
3. **Verify custom test fixes are preserved:**
171-
- `root_unix_test.go`: TestEnvVars uses absolute paths for SSL_CERT_FILE
172-
- `internal_testenv.go`: stub for `internal/testenv` replacement
173-
- Package name: all `*_test.go` must have `package smx509` (not `package x509`)
175+
After sync, verify custom test fixes are preserved:
176+
- `root_unix_test.go`: TestEnvVars uses `filepath.Join(tmpDir, testFile)` for SSL_CERT_FILE
177+
- `internal_testenv.go`: stub for `internal/testenv` replacement
178+
- Package name: all `*_test.go` must have `package smx509`
179+
180+
**If test patches need updating** (stdlib changed the affected code):
181+
```bash
182+
# Manually fix test files in smx509/
183+
# Then regenerate test patches:
184+
go run scripts/smx509/gen_test_patches.go
185+
```
174186

175187
### Step 7: Validate
176188

@@ -192,7 +204,11 @@ go test ./...
192204
### Step 8: Regenerate Patches
193205

194206
```bash
207+
# Source patches
195208
go run scripts/smx509/gen_patches.go
209+
210+
# Test patches
211+
go run scripts/smx509/gen_test_patches.go
196212
```
197213

198214
Verify all 5 patches are regenerated:
@@ -225,8 +241,9 @@ git push origin develop
225241
2. **Baseline is committed**`scripts/smx509/baseline/` is version-controlled, update it explicitly on Go upgrade
226242
3. **`sync.ps1` defaults to `smx509`**`-TargetDir` and `-PackageName` can be omitted for standard usage
227243
4. **PowerShell git ExitCode=1** — PowerShell treats git stderr as error; check actual output, not exit code
228-
5. **Test files NOT in patches**`*_test.go` changes are tracked separately, not in `patches/`
244+
5. **Test files NOT in source patches**`*_test.go` changes are in `test-patches/`, not in `patches/`
229245
6. **`internal/` imports** — any new `internal/*` or `crypto/internal/*` imports in stdlib must be added to `ImportRewriteMap` in `sync.ps1`
246+
7. **Test patches must be regenerated** — if stdlib changed `root_unix_test.go` or test files referencing `testenv`, run `gen_test_patches.go`
230247

231248
## Decision Checklist
232249

@@ -236,6 +253,7 @@ Before merging, verify:
236253
- [ ] `go test ./smx509/...` passes
237254
- [ ] `go test ./pkcs7/... ./cfca/... ./pkcs8/...` passes
238255
- [ ] `gen_patches.go` output matches committed patches (CI check)
256+
- [ ] `gen_test_patches.go` output matches committed test-patches
239257
- [ ] Test files have correct `package smx509`
240258
- [ ] Custom test fixes are re-applied
241259
- [ ] `ImportRewriteMap` updated if stdlib added new internal imports

0 commit comments

Comments
 (0)