Reachability (tools/reachaudit, epic archie-core-06ag) answers "is this code in a shipped binary?". It cannot answer the complementary question: "does every declared contract surface have a consumer, or a declaration that it has none?". ratelimit was in the binary closure and called by nothing, which reachability could not see. tools/contractaudit classifies each subject of each declared surface as CONSUMED, DECLARED-UNCONSUMED, UNDECLARED-UNCONSUMED, or STALE-DECLARATION, and only the last two are findings. The declaration allowlist must match reality exactly: a missing entry fails and so does an entry that outlived its subject, because a stale allowlist is how a gate quietly stops checking anything. Surfaces: the two gRPC services, whose consumption is derived by scanning adapter bodies for calls through the generated client, and the dashboard HTTP API, matched between the registerXRoutes call sites and the path literals the bundled client calls. Findings on the current tree, all deliberate and now declared: ListCaptures and ListUndispatchedCaptures are superseded by their streaming variants -- staterpc's client calls StreamCaptures -- so no production client reaches the unary RPCs. Three bugs this tool found in itself, each recorded because each is the class of error that makes a conformance check worse than none: - Joining RPCs to adapter methods by name silently reported live RPCs as unconsumed, because adapters do not map one-to-one: StoreClient.Get calls GetSession, List calls ListSessions. - Reflecting over the client value rather than the pointer reported zero methods, hence the whole surface unconsumed. - Treating the asset mount and the health probes as dashboard API routes reported four healthy routes as undeclared; they have different consumers and are out of scope for this surface. The consumer extractor fails loudly on a call shape it cannot parse rather than under-reporting, and every check is negative-tested: a route, an RPC, and a removed consumer are each injected, confirmed to fail for the right reason, and reverted. The declaration staleness rule is tested too. Advisory when run directly; task check runs it -strict. See docs/prds/contract-conformance-audit.md.
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
// Command contractaudit reports contract-conformance state across Archie's
|
|
// declared surfaces: which capabilities have a consumer, which have an
|
|
// explicit declaration that they do not, and which have neither.
|
|
//
|
|
// It is the sibling of tools/reachaudit. Reachability asks "is this code in a
|
|
// shipped binary?"; conformance asks "does every declared surface have a
|
|
// consumer, or a declaration that it has none?". A capability can be reachable
|
|
// and unconsumed -- ratelimit was in the binary closure and called by nothing
|
|
// (archie-core-6wxb) -- which reachability cannot see and this can.
|
|
//
|
|
// Advisory by default: it prints, it never deletes or rewrites anything. Pass
|
|
// -strict to fail on an undeclared or stale entry.
|
|
//
|
|
// See docs/prds/contract-conformance-audit.md.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
repoRoot := flag.String("repo-root", "..", "path to the Archie repository root")
|
|
declPath := flag.String(
|
|
"declarations",
|
|
"docs/contract-declarations.json",
|
|
"declaration allowlist, relative to the repository root",
|
|
)
|
|
strict := flag.Bool("strict", false, "fail on undeclared or stale entries")
|
|
jsonOut := flag.Bool("json", false, "emit the report as JSON instead of text")
|
|
flag.Parse()
|
|
|
|
if err := run(*repoRoot, *declPath, *strict, *jsonOut, os.Stdout); err != nil {
|
|
log.Fatalf("contractaudit: %v", err)
|
|
}
|
|
}
|
|
|
|
func run(repoRoot, declPath string, strict, jsonOut bool, out *os.File) error {
|
|
audit, err := New(repoRoot, declPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
findings, err := audit.Run()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if jsonOut {
|
|
if err := writeJSON(out, findings); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
writeText(out, findings)
|
|
}
|
|
if strict && UndeclaredCount(findings) > 0 {
|
|
return fmt.Errorf(
|
|
"%d undeclared or stale contract entries; declare them in %s or consume them",
|
|
UndeclaredCount(findings), declPath,
|
|
)
|
|
}
|
|
return nil
|
|
}
|