fix: fmea/tara project-relative paths + coveragePct clamp + wider FMEA templates (v0.40.0) - #72
Merged
Merged
Conversation
…wider templates x-FuSa spec §4 requires every Finding.Location.File (and the equivalent fmea entries[].file) to be project-relative with forward slashes. Under the common `--dir`-omitted invocation, fmea.Scan's entries[].file and CYBER's own Finding.Location.File (which tara.Scan sources threats[].location/sourceFile directly from) both carried the raw, absolute walked path — reproduced exactly as described against this repo's own source tree (go-FuSa#59). fmea.Scan now relativizes every entry's File against projectRoot; cyber.location now does the same relativization lint/analyze already applied to their own findings (REQ-LOC-REL001), which transitively fixes tara.json too since it had no bug of its own — it only ever inherited an absolute path from the CYBER finding it was built from. x-FuSa spec §9.2 (spec v1.15.0) states coveragePct MUST NOT exceed 100. Both fmea.buildSummary and tara.buildSummary already guaranteed this mathematically via their componentsInProject/assetsInProject >= componentsAnalyzed/assetsAnalyzed fallback, but add an explicit defensive clamp anyway — cheap insurance against a future change to that fallback silently reintroducing the overflow. New regression tests use a fixture with a non-trivial test-source tree (many _test.go files) since a fixture with no such tree can't exercise the exclusion logic the bug depends on. Separately, this repo's own committed fmea.json failed its own new FUSA-STUB002 content-quality gate: deriveAnalysis bucketed every scanned function into one of only 6 fixed template strings, reducing a 461-function codebase to a ~0.013 distinct-value ratio — exactly the "hundreds of FMEA rows sharing identical boilerplate text" pattern §1.6.1 rule B exists to catch (go-FuSa#60). Every template now weaves in the function's own component (a genuine per-function signal) plus, for the dominant no-signal-matched bucket, whether the function has a receiver and how many parameters it takes. Regenerated fmea.json/ fmea.csv: distinct-value ratios are now ~0.28-0.29, well clear of 0.1. Also (x-FuSa spec §1.6 rule 4, SHOULD, non-binding): extracted the vendor/testdata/dot-directory exclusion check duplicated across trace.ScanTags/ScanFuncCoverage/ScanFuncTagCoverage, fmea.CountProjectFunctions, and tara.CountProjectFiles into one shared trace.IsExcludedDir, so the coverage-denominator scanners this issue was actually about stop maintaining an independently-drifting copy. Regenerated tara.json/tara.md for the path fix; tara's own pre-existing FUSA-STUB002 gap (threats[].threat vocabulary, unrelated to this PR) is addressed separately. Signed-off-by: Matt Jones <matt@jellybaby.com> Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
| func TestRunFmea_DirOmitted_EntryFileIsRelative(t *testing.T) { | ||
| dir := t.TempDir() | ||
| src := "package main\n\n//fusa:req REQ-001\nfunc SafetyFunc() error { return nil }\n" | ||
| if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte(src), 0o644); err != nil { |
| func TestRunTara_DirOmitted_ThreatLocationIsRelative(t *testing.T) { | ||
| dir := t.TempDir() | ||
| src := "package main\n\nimport \"crypto/md5\"\n\nfunc Hash(b []byte) [16]byte { return md5.Sum(b) }\n" | ||
| if err := os.WriteFile(filepath.Join(dir, "weak.go"), []byte(src), 0o644); err != nil { |
| // | ||
| //fusa:req REQ-FMEA002 | ||
| func deriveAnalysis(name string, returnsErr, hasGoroutine, hasSafetyReq bool) (modes, effects, causes, mitigations []string, sev Severity) { | ||
| func deriveAnalysis(name, component string, returnsErr, hasGoroutine, hasSafetyReq, hasReceiver bool, paramCount int) (modes, effects, causes, mitigations []string, sev Severity) { |
Resolves conflicts against main after #73 (hara, v0.42.0) merged on top of #69 (tara enum vocabulary, v0.41.0). Bumped this branch's own release to v0.43.0, reordered CHANGELOG.md entries to reflect actual merge order, and regenerated fmea.json/fmea.csv/tara.json/tara.md with the fully-merged binary so they reflect the path-relativization fix, the widened FMEA templates, and the (already-merged) closed impact/risk enums together. Signed-off-by: Matt Jones <matt@jellybaby.com> Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
This was referenced Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces #68 (closed — that branch's rebase-onto-main merge commit was missing DCO sign-off, and my fix attempt used a prohibited force-push). Same content, rebuilt via cherry-pick with no merge commits.
--dir-omitted invocation, violating x-FuSa spec §4's project-relative MUST. Fixed at the root:fmea.Scannow relativizesentries[].file, andcyber.locationnow relativizesFinding.Location.Filethe same way lint/analyze already did — which transitively fixes tara'sthreats[].location/sourceFiletoo, since tara.Scan sources them directly from a CYBER finding.coveragePctMUST NOT exceed 100. Added an explicit defensive clamp in bothfmea.buildSummaryandtara.buildSummary, plus regression tests using a fixture with a non-trivial test-source tree.fmea.jsonfailed its ownFUSA-STUB002content-quality gate (6 fixed templates across 461 functions, ~0.013 distinct-value ratio). WidenedderiveAnalysis's signal set (component, receiver, parameter count) so templates measurably vary by function shape; regeneratedfmea.json/fmea.csv— distinct-value ratios are now ~0.28-0.29.trace.ScanTags/ScanFuncCoverage/ScanFuncTagCoverage,fmea.CountProjectFunctions, andtara.CountProjectFilesinto one sharedtrace.IsExcludedDir.Closes #59, closes #60. Addresses x-FuSa spec v1.15.0 items 2 and 3 from #64 (item 1, attestation carry-forward, is in a separate PR).
Test plan
go build ./...go vet ./...go test -race -count=1 ./...golangci-lint run ./...(0 issues)fmea.json/tara.jsonentries now use relative paths, never absolute--diromitted), coveragePct-clamp regression tests with a non-trivial test-source tree,IsExcludedDirunit tests