Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test(api-types): the header census matches X-PinchTab-* case-insensitively and pins the bare prefix, so a canonical-case or assembled duplicate is caught

Luigi Agosti7feee63fdb14
diff --git a/internal/api/types/headers_census_test.go b/internal/api/types/headers_census_test.go
index 18470d63..12b332ff 100644
--- a/internal/api/types/headers_census_test.go
+++ b/internal/api/types/headers_census_test.go
@@ -24,14 +24,33 @@ const (
// allows its one spelling to sit in the named file rather than in api/types. A new wire
// header must go in headers.go instead of being added here.
var exemptHeaders = map[string]string{
- "X-PinchTab-Internal-Token": "internal/handlers/trust.go: server-only trusted-hop token, never part of the CLI/MCP wire contract",
- "X-PinchTab-Event": "internal/scheduler/webhook.go: outbound event-webhook contract, separate from the wire headers",
- "X-PinchTab-Task-ID": "internal/scheduler/webhook.go: outbound event-webhook contract, separate from the wire headers",
- "X-PinchTab-Session-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
- "X-PinchTab-Instance-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
- "X-PinchTab-Profile-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
- "X-PinchTab-Profile-Name": "internal/activity/context.go: activity-only identity header, already single-homed",
- "X-PinchTab-Tab-Created": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-PinchTab-Internal-Token": "internal/handlers/trust.go: server-only trusted-hop token, never part of the CLI/MCP wire contract",
+ "X-PinchTab-Event": "internal/scheduler/webhook.go: outbound event-webhook contract, separate from the wire headers",
+ "X-PinchTab-Task-ID": "internal/scheduler/webhook.go: outbound event-webhook contract, separate from the wire headers",
+ "X-PinchTab-Session-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-PinchTab-Instance-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-PinchTab-Profile-Id": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-PinchTab-Profile-Name": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-PinchTab-Tab-Created": "internal/activity/context.go: activity-only identity header, already single-homed",
+ "X-Pinchtab-Failure-Code": "internal/httpx/httpx.go: failure reason stamped by an instance for the front door and stripped at the public boundary",
+ "X-Pinchtab-Failure-Message": "internal/httpx/httpx.go: failure reason stamped by an instance for the front door and stripped at the public boundary",
+ "X-Pinchtab-Proxy-Authorization": "internal/proxy/proxy_ws.go: backend credential on the server-only websocket proxy hop",
+ "X-Pinchtab-": "internal/handlers/trust.go: the prefix the ingress strip matches, not a header name; a second copy is a header assembled from parts",
+ "x-pinchtab-enabled": "internal/handlers/openapi.go: OpenAPI vendor extension key, not an HTTP header",
+ "x-pinchtab-security": "internal/handlers/openapi.go: OpenAPI vendor extension key, not an HTTP header",
+}
+
+func headerKey(name string) string {
+ return strings.ToLower(name)
+}
+
+func isExempt(header string) bool {
+ for name := range exemptHeaders {
+ if headerKey(name) == header {
+ return true
+ }
+ }
+ return false
}
// pinchtabHeaderLiterals maps each X-PinchTab-* string literal to the module-relative files
@@ -51,8 +70,8 @@ func pinchtabHeaderLiterals(t *testing.T, files []srccensus.SourceFile) map[stri
return true
}
val, err := strconv.Unquote(lit.Value)
- if err == nil && strings.HasPrefix(val, "X-PinchTab-") {
- out[val] = append(out[val], f.Name)
+ if err == nil && strings.HasPrefix(headerKey(val), "x-pinchtab-") {
+ out[headerKey(val)] = append(out[headerKey(val)], f.Name)
}
return true
})
@@ -68,7 +87,7 @@ func singleHomeViolations(headers map[string][]string) []string {
violations = append(violations, fmt.Sprintf("%s is spelled in %d places, want exactly one so a one-character drift is a compile error, not a silent no-op: %v", header, len(locs), locs))
continue
}
- if _, exempt := exemptHeaders[header]; exempt {
+ if isExempt(header) {
if locs[0] == headerHomeFile {
violations = append(violations, fmt.Sprintf("%s is listed as exempt but sits in the wire-header home %s", header, headerHomeFile))
}
@@ -86,7 +105,7 @@ func TestEachWireHeaderLiteralIsSingleHomed(t *testing.T) {
headers := pinchtabHeaderLiterals(t, srccensus.Tree(t, moduleRoot, minModuleFiles))
for _, wire := range []string{HeaderVocab, HeaderTabID, HeaderSource} {
- locs := headers[wire]
+ locs := headers[headerKey(wire)]
if len(locs) != 1 || locs[0] != headerHomeFile {
t.Errorf("wire header %s must be spelled exactly once, in %s; found %v", wire, headerHomeFile, locs)
}
@@ -104,20 +123,32 @@ func TestCensusFlagsADuplicateSpelling(t *testing.T) {
{Name: "internal/somewhere/dup.go", Text: "package somewhere\nconst B = \"X-PinchTab-Vocab\"\n"},
}
headers := pinchtabHeaderLiterals(t, planted)
- if len(headers["X-PinchTab-Vocab"]) != 2 {
- t.Fatalf("the AST census did not see the planted duplicate: %v", headers["X-PinchTab-Vocab"])
+ if len(headers[headerKey(HeaderVocab)]) != 2 {
+ t.Fatalf("the AST census did not see the planted duplicate: %v", headers[headerKey(HeaderVocab)])
}
if len(singleHomeViolations(headers)) == 0 {
t.Fatal("a duplicated wire-header spelling passed the census; a typo on one side would silently disable the feature")
}
}
+func TestCensusFlagsADuplicateInAnotherCase(t *testing.T) {
+ for _, spelling := range []string{"X-Pinchtab-Vocab", "x-pinchtab-vocab"} {
+ planted := []srccensus.SourceFile{
+ {Name: headerHomeFile, Text: "package types\nconst A = \"X-PinchTab-Vocab\"\n"},
+ {Name: "internal/somewhere/dup.go", Text: "package somewhere\nconst B = \"" + spelling + "\"\n"},
+ }
+ if len(singleHomeViolations(pinchtabHeaderLiterals(t, planted))) == 0 {
+ t.Errorf("%q passed the census as a new header, but HTTP header names are case-insensitive, so it names the same wire header", spelling)
+ }
+ }
+}
+
// A comment that names a header is not a spelling: the AST walk sees literals only.
func TestCensusIgnoresHeadersNamedInComments(t *testing.T) {
commentOnly := []srccensus.SourceFile{
{Name: "internal/foo/foo.go", Text: "package foo\n// mentions X-PinchTab-Vocab in prose only\nconst X = 1\n"},
}
- if got := pinchtabHeaderLiterals(t, commentOnly)["X-PinchTab-Vocab"]; len(got) != 0 {
+ if got := pinchtabHeaderLiterals(t, commentOnly)[headerKey(HeaderVocab)]; len(got) != 0 {
t.Fatalf("a header named only in a comment was counted as a spelling: %v", got)
}
}