-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(receipt): Exposure Receipt in qmax-code — LLM + cloud-API egress (QUA-1316) #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
90a78c3
e7219a7
25d9fde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| receipt "github.com/Quality-Max/qmax-receipt" | ||
| ) | ||
|
|
||
| // handleReceiptCommand implements `qmax-code receipt <list|show|verify> [id|latest]` | ||
| // — the customer-facing surface for the Exposure Receipt: "here is exactly what | ||
| // left your network this session, and it verifies offline." verify is fully | ||
| // offline and prints the provenance-not-honesty caveat. | ||
| func handleReceiptCommand(args []string) { | ||
| initReceiptPaths() | ||
|
|
||
| sub := "list" | ||
| if len(args) > 0 { | ||
| sub = args[0] | ||
| } | ||
| switch sub { | ||
| case "list": | ||
| receiptList() | ||
| case "show": | ||
| receiptShow(argAt(args, 1)) | ||
| case "verify": | ||
| receiptVerify(argAt(args, 1)) | ||
| default: | ||
| fmt.Fprintln(os.Stderr, "Usage: qmax-code receipt <list|show|verify> [id|latest]") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new Add a test file Example: Suggested fix: func TestReceiptVerifyMissingId(t *testing.T) {
// Mock receipt.Load to return error
// Call handleReceiptCommand with args ["verify", "non-existent"]
// Assert stderr contains error and os.Exit(1) is called (use os.Exit override)
}Why this wasn't caught: The sibling mapping shows no test file for cmd_receipt.go in this PR. More Info
Prompt To Fix With AI |
||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func argAt(args []string, i int) string { | ||
| if len(args) > i { | ||
| return args[i] | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func receiptList() { | ||
| paths, err := receipt.List() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| if len(paths) == 0 { | ||
| fmt.Println("No exposure receipts found.") | ||
| return | ||
| } | ||
| fmt.Printf("%-34s %-20s %-8s %s\n", "RUN ID", "KIND", "REQUESTS", "DESTINATIONS") | ||
| for _, p := range paths { | ||
| r, err := receipt.Load(p) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| fmt.Printf("%-34s %-20s %-8d %v\n", r.RunID, r.RunKind, r.Summary.TotalRequests, r.Destinations) | ||
| } | ||
| } | ||
|
|
||
| func receiptShow(idOrLatest string) { | ||
| r := mustResolveReceipt(idOrLatest) | ||
| data, err := json.MarshalIndent(r, "", " ") | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: cannot marshal receipt: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Println(string(data)) | ||
| } | ||
|
|
||
| func receiptVerify(idOrLatest string) { | ||
| r := mustResolveReceipt(idOrLatest) | ||
| if err := receipt.Verify(r); err != nil { | ||
| fmt.Fprintf(os.Stderr, "✗ INVALID: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("✓ VALID — run %s (%s), %d request(s) across %v\n", | ||
| r.RunID, r.RunKind, r.Summary.TotalRequests, r.Destinations) | ||
| fmt.Println("Note: this proves the receipt was produced by this agent's key (provenance),") | ||
| fmt.Println("not that the agent disclosed everything. Cross-check against your own egress logs.") | ||
| } | ||
|
|
||
| func mustResolveReceipt(idOrLatest string) *receipt.Receipt { | ||
| dir, err := receipt.ReceiptsDir() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| if idOrLatest == "" || idOrLatest == "latest" { | ||
| paths, err := receipt.List() | ||
|
Comment on lines
+85
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In More Info
Prompt To Fix With AI |
||
| if err != nil || len(paths) == 0 { | ||
| fmt.Fprintln(os.Stderr, "No exposure receipts found.") | ||
| os.Exit(1) | ||
| } | ||
| r, err := receipt.Load(paths[len(paths)-1]) | ||
| if err != nil { | ||
|
Comment on lines
+85
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Flagged by 2 specialists. Example: Suggested fix: if !receiptIDPattern.MatchString(idOrLatest) {
fmt.Fprintf(os.Stderr, "invalid receipt ID: %s\n", idOrLatest)
os.Exit(1)
}
r, err := receipt.Load(filepath.Join(dir, idOrLatest+".json"))Why this wasn't caught: No test exercises Detailed reasoning
While this is a local CLI tool running with the user's own permissions (so there's no privilege escalation), the tool is positioned as security-aware ('Receipts, not promises'). The function should validate that More Info
Prompt To Fix With AI |
||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
|
Check warning on line 100 in cmd_receipt.go
|
||
| } | ||
| return r | ||
| } | ||
| r, err := receipt.Load(filepath.Join(dir, idOrLatest+".json")) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| return r | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file
cmd_receipt.goimplements theqmax-code receiptsubcommand with three subcommands (list,show,verify) and helper functions. It contains non-trivial logic for parsing arguments, resolving receipt IDs, loading and displaying receipts, and error handling. The PR adds this as a new customer-facing surface but does not include a sibling test file. Without tests, regressions in argument parsing, error paths, or the 'latest' resolution logic could silently break the command.Example:
Suggested fix:
Why this wasn't caught: The source file has no sibling test in this PR.
More Info
cmd_receipt.gowith functionshandleReceiptCommand,receiptList,receiptShow,receiptVerify,mustResolveReceipt.cmd_receipt_test.gowith unit tests for each subcommand, including edge cases (no receipts, invalid ID, 'latest' resolution, error paths).Prompt To Fix With AI