zjncs opened a new pull request, #5614:
URL: https://github.com/apache/rocketmq-dashboard/pull/5614
Closes #5613
## Problem
The single-file (`-input`) branch of `cataloggen` redeclared `source` with
`:=` inside the else block, shadowing the outer `var source []byte`. In
`-input` mode the outer variable stayed nil, so:
- `sha256.Sum256(source)` computed **sha256 of the empty string** — a
constant (`e3b0c442...`) baked into the generated catalog's `Digest` and the
markdown output, regardless of the actual input
- `renderSDKContract(source)` rendered the SDK contract as literal `null\n`,
silently destroying the generated tools document
The existing tests exercise `-input` but never check the digest or pass
`-sdk`, which is why this survived. (Live repro on master: `go run ./generate
-input in.yaml -output catalog_gen.go -sdk sdk.json` → empty-string digest +
`sdk.json` containing `null`.)
## Fix
Assign to the outer variable in the single-file branch (renaming the inner
read to `content`), exactly as the merged-shards branch already does:
```go
content, err := os.ReadFile(inputPath)
if err != nil { return fmt.Errorf("read catalog: %w", err) }
source = content
```
## Verification
- New `singlefile_test.go`: runs `-input ... -sdk ...`, asserts the
generated catalog contains `sha256(input)` (and not the empty-string digest)
and the SDK JSON contains the tools (not `null`) — **FAILS on master**
(`generated catalog digest does not match sha256 of the input source`),
**PASSES with this change**
- Mutation check: stashing only the `main.go` fix makes the test fail again;
restoring it passes (`-count=1` throughout — the generator runs as a
subprocess, so the test cache can mask red/green)
- Regression: full `./internal/catalog/...` suite green (`ok` for both
packages); `go vet` clean
## Collision note
No open PR touches `rmqctl/internal/catalog/generate/main.go` (our own
#5602/#5604 are confined to `rmqctl/scripts/`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]