Skip to content

feat: v0.5.46 — x-FuSa spec v1.13.0/v1.14.0 conformance - #72

Merged
SoundMatt merged 3 commits into
mainfrom
feat/xfusa-v1-14-conformance
Jul 28, 2026
Merged

feat: v0.5.46 — x-FuSa spec v1.13.0/v1.14.0 conformance#72
SoundMatt merged 3 commits into
mainfrom
feat/xfusa-v1-14-conformance

Conversation

@SoundMatt

Copy link
Copy Markdown
Owner

Summary

Closes #71. Brings hara/fmea/tara/safety-case/sas/sci into conformance with x-FuSa spec §1.2.5/§9.2/§9.3 schemas, implements the §1.6/§1.6.1/§1.6.2 content-quality baseline (FUSA-STUB001/002 detection + attestation), and adds summary.coveragePct/--min-coverage to fmea/tara.

  • .fusa-hara.json now has the three cross-referenced collections (operationalSituations[]/hazards[]/safetyGoals[]), with safetyGoals[].fssrRefs as a MUST, ≥1 entry field cross-checked against .fusa-reqs.json. hara init scaffolds empty collections (never dummy rows); hara show/--format json add a completeness block.
  • fmea.json: ratingScale, per-function-templated failureMode/effect/cause (varies with the actual function found — not one canned string), actionPriority, summary.componentsInProject/coveragePct.
  • tara.json: an SFOP impact object (safety/financial/operational/privacy) instead of one generic severity; assets/threats are now discovered by scanning for network/file/auth/memory-input functions instead of a placeholder-filled template.
  • safety-case --format json is new: nodes[]/edges[]/completeness using the six real GSN node types; solution nodes only cite evidence that actually exists.
  • sas --format json: checklist[]/summary, present reflects a real evidence-file check; always also writes the sas.md companion.
  • sci --format json: filesartifacts, sha256hash (sha256:-prefixed per §2.7).
  • New qualitybar module: FUSA-STUB001 (always ERROR, disposition-suppressible only) and FUSA-STUB002 (WARNING by default, attestation-suppressible), wired into hara/fmea/tara/safety-case/sas via new --strict/--require-attestation/--attest <reviewer> flags.
  • --min-coverage N on fmea/tara, mirroring trace --func-coverage; excludes test files from the denominator.
  • Regenerated this repo's own .fusa-hara.json (migrated off the retired .cfusa-hara.json, with corrected ASIL values), fmea.json/fmea.csv, tara.json/tara.md, and added safety-case.json — dogfooding the new schemas.
  • Along the way: fixed a real invalid-JSON/CSV bug in fmea (an unescaped function-name false-positive), updated cmd_safety_rules.c's HARA002/003/004 engine rules for the new schema, and fixed two self-inflicted CFUSA-CY002 false positives.

Test plan

  • ctest --test-dir build — 39/39 test binaries pass, including new tests/test_xfusa_v114.c
  • lcov/cfusa coverage --threshold 80 — 85.0% line coverage (gate: 80%)
  • cfusa hara/fmea/tara/safety-case --format json output validated as well-formed JSON (python3 -m json.tool) and free of FUSA-STUB001-pattern placeholder text
  • cfusa check --dir . shows no new findings attributable to this change (fixed 2 self-inflicted CY002 false positives)

…ra/safety-case/sas/sci schemas, content-quality baseline, coverage metrics)

Closes #71.

Schema conformance (x-FuSa spec §1.2.5/§9.2/§9.3):
- .fusa-hara.json: three cross-referenced collections
  (operationalSituations[]/hazards[]/safetyGoals[]) replace the old flat
  hazards[] shape; safetyGoals[].fssrRefs is now MUST/>=1 entry, cross-
  checked against .fusa-reqs.json. `hara init` scaffolds empty collections
  (never dummy rows); `hara show`/--format json add a completeness block.
- fmea.json: ratingScale, per-function-templated failureMode/effect/cause
  (varies with the actual function found, not a fixed string), actionPriority,
  summary.componentsInProject/coveragePct.
- tara.json: SFOP impact object (safety/financial/operational/privacy) per
  ISO 21434 Clause 15.7 instead of one generic severity; assets/threats are
  now discovered by scanning for network/file/auth/memory-input functions
  instead of a placeholder-filled template; summary.assetInventoryMethod.
- safety-case --format json is new: nodes[]/edges[]/completeness using the
  six real GSN node types; solution nodes only cite evidence that actually
  exists in the project.
- sas --format json: checklist[]/summary, `present` reflects a real
  evidence-file check; always also writes the sas.md companion.
- sci --format json: files→artifacts, sha256→hash (sha256:-prefixed per
  §2.7 — a field named "hash" carries an algorithm-prefixed value, unlike
  a field named for its algorithm).

Content-quality baseline (§1.6/§1.6.1/§1.6.2):
- New qualitybar module: FUSA-STUB001 (always ERROR, a placeholder/
  template-text deny-list scan; suppressible only via
  .fusa-dispositions.json, never attestation) and FUSA-STUB002 (WARNING by
  default, a distinct-value-ratio check across >=10 entries), wired into
  hara/fmea/tara/safety-case/sas.
- --strict/--require-attestation and --attest <reviewer> on the same five
  commands. A non-stale, genuinely-independent attestation (content hash
  matches the artifact's current substantive content) suppresses
  FUSA-STUB002; a self-attestation or a stale hash falls back to
  "heuristic" (fail-safe).

Coverage metrics:
- --min-coverage N on fmea/tara (mirrors trace --func-coverage); N=0
  disables the gate. componentsInProject/assetsInProject exclude test
  files, matching trace --func-coverage's own denominator.

Fixes found along the way:
- fmea.json/fmea.csv could contain invalid JSON/CSV when the function-name
  scanner misdetected a quoted string literal as a function name — every
  free-text field is now escaped for its target format.
- cmd_safety_rules.c's HARA002/003/004 engine rules still read the old flat
  .fusa-hara.json shape; updated to the new nested fields and scoped to the
  hazards/safetyGoals arrays so they don't cross-match a same-named nested
  key in a sibling collection.
- Two spurious CFUSA-CY002 (uncontrolled format string) false positives in
  my own new fprintf-in-macro calls, caused by a line-continuation
  backslash landing between the FILE* arg and the format-string literal.

Regenerated this repo's own .fusa-hara.json (migrated from the retired
.cfusa-hara.json, including recomputed ASIL values), fmea.json/fmea.csv,
tara.json/tara.md, and added safety-case.json against the new schemas —
c-FuSa dogfooding its own spec conformance work.

New tests: tests/test_xfusa_v114.c (qualitybar unit tests + per-command
schema/coverage/attestation integration tests); updated test_safety_rules.c
fixtures and test_gap_coverage.c assertions for the new field names.
39/39 test binaries pass; line coverage 85.0% (gate: 80%).

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfusa found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Comment thread cmd/cfusa/cmd_safety_case.c Fixed
Comment thread cmd/cfusa/cmd_sas.c Fixed
Comment thread tests/test_xfusa_v114.c Fixed
Comment thread tests/test_xfusa_v114.c Fixed
Comment thread tests/test_xfusa_v114.c Fixed
Comment thread cmd/cfusa/cmd_hara.c
const char *start = p, *end = NULL;
for (; *p; p++) {
if (in_str) {
if (*p == '\\') { p++; continue; }
Comment thread cmd/cfusa/cmd_hara.c
int depth = 0, in_str = 0;
for (; *p; p++) {
if (in_str) {
if (*p == '\\') { p++; continue; }
Comment thread cmd/cfusa/cmd_hara.c
}
if (*p == '"') { in_str = 1; continue; }
if (*p == '{') depth++;
else if (*p == '}') { depth--; if (depth == 0) { p++; break; } }
const char *start = p;
for (; *p; p++) {
if (in_str) {
if (*p == '\\') { p++; continue; }
Comment thread src/qualitybar.c
const char *doc_end = json + len;
for (; p < doc_end && *p; p++) {
if (in_str) {
if (*p == '\\') { p++; continue; }
…deQL)

CodeQL flagged 5 high-severity "file created with default (potentially
0666) permissions" alerts across the files this PR touched: fopen(path,
"w") relies on the process umask for its actual mode, whereas
open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600) is explicit and doesn't depend
on umask. cmd_capabilities.c already established this pattern in the
codebase for the same reason; added a shared cfusa_fopen_write() helper in
utils.c and switched every fopen(..., "w") call in the files this PR
introduced/rewrote (hara/fmea/tara/safety-case/sas/sci, plus the new
test file) to use it.

Regenerated fmea.json/fmea.csv/tara.json/tara.md/safety-case.{json,md}
after the utils.c change (function count shifted slightly since
cfusa_fopen_write itself is now part of the public-function surface FMEA
scans).

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Comment thread src/utils.c Fixed
…n Linux

cfusa_fopen_write() (added in the previous commit) calls open()/fdopen().
Without _POSIX_C_SOURCE, strict -std=c99 glibc headers hide fdopen()'s
prototype, so gcc/clang implicitly declare it as returning `int`; the
truncated 32-bit "pointer" assigned to a FILE* then segfaults on first
use. Every other file in this codebase that calls open()/fdopen() already
carries this exact guard (cmd_capabilities.c, cmd_qualify.c, cmd_impact.c,
cmd_release.c, cmd_audit_pack.c) — utils.c was the one new call site that
missed it, and every test binary that exercises hara/fmea/tara/
safety-case/sas (all of which now route through cfusa_fopen_write)
segfaulted on Linux CI as a result (macOS's libc doesn't gate fdopen() on
the C standard version, so this passed locally and on the macOS runner).

Reproduced and confirmed fixed in an ubuntu:22.04 container (39/39 test
binaries, including the 7 that segfaulted in CI: test_hara,
test_safety_commands, test_cli_commands, test_commands2,
test_hara_advanced, test_gap_coverage, test_xfusa_v114).

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants