refactor(cli): drop the always-empty interface_metadata wire projection
embeddedMCPMetadata only feeds interface validation now; its summary was projected onto every schema payload as a constant-empty blob. Remove the SchemaRegistry field, all three payload projections, the snapshot wire field, the overview copy, the compact strip entry, and the jq policy gate. Also delete the redundant io.Discard dead-code suppressor in event_command.go (io has five genuine uses there).
This commit is contained in:
@@ -1411,7 +1411,3 @@ func eventTypesWithDefault(types []string) []string {
|
||||
}
|
||||
return registry.CatchAllEventTypes()
|
||||
}
|
||||
|
||||
// compile-time guard: avoid "imported and not used" if any of these
|
||||
// indirect imports become unused after future refactors.
|
||||
var _ = io.Discard
|
||||
|
||||
@@ -115,22 +115,6 @@ func emptyPinnedMCPMetadata() embeddedMCPMetadata {
|
||||
return embeddedMCPMetadata{Tools: map[string]embeddedMCPToolMetadata{}}
|
||||
}
|
||||
|
||||
func interfaceMetadataSummaryFrom(metadata embeddedMCPMetadata) map[string]any {
|
||||
summary := map[string]any{
|
||||
"source": strings.TrimSpace(metadata.Source),
|
||||
"version": metadata.Version,
|
||||
"source_hash": strings.TrimSpace(metadata.SourceHash),
|
||||
"tool_count": len(metadata.Tools),
|
||||
}
|
||||
if revision := strings.TrimSpace(metadata.SourceRevision); revision != "" {
|
||||
summary["source_revision"] = revision
|
||||
}
|
||||
if metadata.Coverage.SurfaceTools > 0 {
|
||||
summary["coverage"] = metadata.Coverage
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
// applyContractRiskToSafety overlays Schema Safety fields from an embedded
|
||||
// Contract Risk value. Path A: Contract wins effect/risk/confirmation for the
|
||||
// managed surface; other Safety fields (e.g. idempotency) are preserved.
|
||||
@@ -1309,7 +1293,6 @@ var schemaCompactStripKeys = map[string]bool{
|
||||
"metadata_source": true,
|
||||
"source": true,
|
||||
"agent_metadata": true,
|
||||
"interface_metadata": true,
|
||||
"field_provenance": true,
|
||||
"reviewed": true,
|
||||
// redundant with canonical_path / cli_path
|
||||
|
||||
@@ -454,51 +454,6 @@ func TestRuntimeSchemaAllPayloadContainsFullLeafParameters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeSchemaReportsPinnedInterfaceMetadata(t *testing.T) {
|
||||
mcpFixture := embeddedMCPMetadata{
|
||||
Version: 1,
|
||||
Source: "cli-registry",
|
||||
SourceRevision: "revision-test",
|
||||
SourceHash: "sha256:interface-test",
|
||||
Coverage: embeddedMCPMetadataCoverage{
|
||||
SurfaceScope: "source_revision",
|
||||
SourceTools: 10,
|
||||
SurfaceTools: 2,
|
||||
MatchedTools: 1,
|
||||
UnmatchedTools: 1,
|
||||
},
|
||||
Tools: map[string]embeddedMCPToolMetadata{
|
||||
"doc.create_document": {Description: "创建文档"},
|
||||
},
|
||||
}
|
||||
agentFixture := emptyAgentMetadata()
|
||||
|
||||
catalog, err := runtimeSchemaPayloadForTestWithMetadata(buildRuntimeSchemaTestRoot(), nil, agentFixture, mcpFixture)
|
||||
if err != nil {
|
||||
t.Fatalf("runtimeSchemaPayloadForTest(catalog): %v", err)
|
||||
}
|
||||
summary, _ := catalog["interface_metadata"].(map[string]any)
|
||||
if summary["source"] != "cli-registry" || summary["source_hash"] != "sha256:interface-test" || schemaTestInt(summary["tool_count"]) != 1 {
|
||||
t.Fatalf("interface metadata summary = %#v", summary)
|
||||
}
|
||||
coverage, _ := summary["coverage"].(map[string]any)
|
||||
if summary["source_revision"] != "revision-test" || coverage["surface_scope"] != "source_revision" || schemaTestInt(coverage["surface_tools"]) != 2 {
|
||||
t.Fatalf("interface metadata provenance = %#v", summary)
|
||||
}
|
||||
|
||||
registry, err := schemaRegistryForTestWithMetadata(buildRuntimeSchemaTestRoot(), agentFixture, mcpFixture)
|
||||
if err != nil {
|
||||
t.Fatalf("schemaRegistryForTest(): %v", err)
|
||||
}
|
||||
compact, err := registry.ToOverviewPayload()
|
||||
if err != nil {
|
||||
t.Fatalf("ToOverviewPayload(): %v", err)
|
||||
}
|
||||
if compact["interface_metadata"] == nil {
|
||||
t.Fatalf("compact schema dropped interface metadata: %#v", compact)
|
||||
}
|
||||
}
|
||||
|
||||
func schemaTestInt(value any) int {
|
||||
switch typed := value.(type) {
|
||||
case int:
|
||||
|
||||
@@ -592,8 +592,8 @@ func TestStripSchemaPayloadCompactOverview(t *testing.T) {
|
||||
t.Fatalf("compact overview missing key %q", key)
|
||||
}
|
||||
}
|
||||
// Must strip agent_metadata / interface_metadata at top level.
|
||||
for _, key := range []string{"agent_metadata", "interface_metadata", "source"} {
|
||||
// Must strip agent_metadata at top level.
|
||||
for _, key := range []string{"agent_metadata", "source"} {
|
||||
if _, ok := stripped[key]; ok {
|
||||
t.Fatalf("compact overview still contains stripped key %q", key)
|
||||
}
|
||||
|
||||
@@ -29,13 +29,12 @@ import (
|
||||
// the outer boundary by ToPayload. This keeps map[string]any out of the
|
||||
// contract assembly path.
|
||||
type SchemaRegistry struct {
|
||||
Kind string
|
||||
Level string
|
||||
Source string
|
||||
Products []ProductSpec
|
||||
InterfaceMetadata json.RawMessage
|
||||
AgentMetadata json.RawMessage
|
||||
Extensions map[string]json.RawMessage
|
||||
Kind string
|
||||
Level string
|
||||
Source string
|
||||
Products []ProductSpec
|
||||
AgentMetadata json.RawMessage
|
||||
Extensions map[string]json.RawMessage
|
||||
}
|
||||
|
||||
// ProductSpec is one deterministic product grouping in SchemaRegistry.
|
||||
@@ -492,9 +491,6 @@ func (r SchemaRegistry) ToSnapshotPayload() (SchemaSnapshotPayload, error) {
|
||||
if r.Source != "" {
|
||||
catalog["source"] = r.Source
|
||||
}
|
||||
if err := putRawJSON(catalog, "interface_metadata", r.InterfaceMetadata); err != nil {
|
||||
return SchemaSnapshotPayload{}, fmt.Errorf("interface_metadata: %w", err)
|
||||
}
|
||||
if err := putRawJSON(catalog, "agent_metadata", r.AgentMetadata); err != nil {
|
||||
return SchemaSnapshotPayload{}, fmt.Errorf("agent_metadata: %w", err)
|
||||
}
|
||||
@@ -833,9 +829,6 @@ func (r SchemaRegistry) ToPayload() (map[string]any, error) {
|
||||
if r.Source != "" {
|
||||
payload["source"] = r.Source
|
||||
}
|
||||
if err := putRawJSON(payload, "interface_metadata", r.InterfaceMetadata); err != nil {
|
||||
return nil, fmt.Errorf("interface_metadata: %w", err)
|
||||
}
|
||||
if err := putRawJSON(payload, "agent_metadata", r.AgentMetadata); err != nil {
|
||||
return nil, fmt.Errorf("agent_metadata: %w", err)
|
||||
}
|
||||
@@ -879,9 +872,6 @@ func (r SchemaRegistry) ToOverviewPayload() (map[string]any, error) {
|
||||
if r.Source != "" {
|
||||
payload["source"] = r.Source
|
||||
}
|
||||
if err := putRawJSON(payload, "interface_metadata", r.InterfaceMetadata); err != nil {
|
||||
return nil, fmt.Errorf("interface_metadata: %w", err)
|
||||
}
|
||||
if err := putRawJSON(payload, "agent_metadata", r.AgentMetadata); err != nil {
|
||||
return nil, fmt.Errorf("agent_metadata: %w", err)
|
||||
}
|
||||
|
||||
@@ -117,9 +117,8 @@ func TestCrossPlatformCoverageSchemaSnapshotRendererDependencyEdges(t *testing.T
|
||||
snapshotProductSummary = oldProductSummary
|
||||
|
||||
for name, candidate := range map[string]SchemaRegistry{
|
||||
"extensions": {Extensions: map[string]json.RawMessage{"bad": json.RawMessage(`{`)}},
|
||||
"interface metadata": {InterfaceMetadata: json.RawMessage(`{`)},
|
||||
"agent metadata": {AgentMetadata: json.RawMessage(`{`)},
|
||||
"extensions": {Extensions: map[string]json.RawMessage{"bad": json.RawMessage(`{`)}},
|
||||
"agent metadata": {AgentMetadata: json.RawMessage(`{`)},
|
||||
} {
|
||||
if _, err := candidate.ToSnapshotPayload(); err == nil {
|
||||
t.Errorf("%s error was nil", name)
|
||||
@@ -230,7 +229,6 @@ func TestCrossPlatformCoverageContractModelPayloadErrorEdges(t *testing.T) {
|
||||
for name, registry := range map[string]SchemaRegistry{
|
||||
"product": {Products: []ProductSpec{{ID: "sample", Extensions: map[string]json.RawMessage{"bad": badRaw}}}},
|
||||
"registry extension": {Extensions: map[string]json.RawMessage{"bad": badRaw}},
|
||||
"interface metadata": {InterfaceMetadata: badRaw},
|
||||
"agent metadata": {AgentMetadata: badRaw},
|
||||
} {
|
||||
if _, err := registry.ToPayload(); err == nil {
|
||||
@@ -238,8 +236,7 @@ func TestCrossPlatformCoverageContractModelPayloadErrorEdges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for name, registry := range map[string]SchemaRegistry{
|
||||
"interface metadata": {InterfaceMetadata: badRaw},
|
||||
"agent metadata": {AgentMetadata: badRaw},
|
||||
"agent metadata": {AgentMetadata: badRaw},
|
||||
} {
|
||||
if _, err := registry.ToOverviewPayload(); err == nil {
|
||||
t.Errorf("overview %s error was nil", name)
|
||||
|
||||
@@ -331,10 +331,8 @@ func schemaOverviewPayloadFromCatalog(catalog map[string]any) map[string]any {
|
||||
if source := schemaString(catalog["source"]); source != "" {
|
||||
payload["source"] = source
|
||||
}
|
||||
for _, key := range []string{"interface_metadata", "agent_metadata"} {
|
||||
if value, exists := catalog[key]; exists {
|
||||
payload[key] = value
|
||||
}
|
||||
if value, exists := catalog["agent_metadata"]; exists {
|
||||
payload["agent_metadata"] = value
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -219,8 +219,7 @@ func TestSchemaOverviewPayloadFromCatalogPreservesListSelectionPriority(t *testi
|
||||
"tools": []map[string]any{{}, {}},
|
||||
},
|
||||
},
|
||||
"interface_metadata": map[string]any{"coverage": "complete"},
|
||||
"agent_metadata": map[string]any{"coverage": "reviewed"},
|
||||
"agent_metadata": map[string]any{"coverage": "reviewed"},
|
||||
}
|
||||
|
||||
got := schemaOverviewPayloadFromCatalog(catalog)
|
||||
@@ -235,7 +234,7 @@ func TestSchemaOverviewPayloadFromCatalogPreservesListSelectionPriority(t *testi
|
||||
if got["count"] != 3 || got["tool_count"] != 3 || got["source"] != "runtime-assembled" {
|
||||
t.Fatalf("overview envelope = %#v", got)
|
||||
}
|
||||
if !schemaJSONEqual(got["interface_metadata"], catalog["interface_metadata"]) || !schemaJSONEqual(got["agent_metadata"], catalog["agent_metadata"]) {
|
||||
if !schemaJSONEqual(got["agent_metadata"], catalog["agent_metadata"]) {
|
||||
t.Fatalf("overview metadata = %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,17 +447,6 @@ func TestCrossPlatformCoverageResolveAssembleInjectionErrors(t *testing.T) {
|
||||
assembleMarshalRaw = func(any) (json.RawMessage, error) {
|
||||
calls++
|
||||
if calls == 1 {
|
||||
return nil, fmt.Errorf("iface boom")
|
||||
}
|
||||
return json.RawMessage(`{}`), nil
|
||||
}
|
||||
if _, err := assembleSchemaRegistryFromBound(BoundCommandRegistry{}, runtimeSchemaMetadataSources{}); err == nil || !strings.Contains(err.Error(), "iface boom") {
|
||||
t.Fatalf("iface marshal error = %v", err)
|
||||
}
|
||||
calls = 0
|
||||
assembleMarshalRaw = func(any) (json.RawMessage, error) {
|
||||
calls++
|
||||
if calls == 2 {
|
||||
return nil, fmt.Errorf("agent boom")
|
||||
}
|
||||
return json.RawMessage(`{}`), nil
|
||||
|
||||
@@ -196,10 +196,6 @@ func assembleSchemaRegistryFromBoundWithOptions(bound BoundCommandRegistry, meta
|
||||
if err != nil {
|
||||
return SchemaRegistry{}, fmt.Errorf("build typed Schema registry: %w", err)
|
||||
}
|
||||
registry.InterfaceMetadata, err = assembleMarshalRaw(interfaceMetadataSummaryFrom(metadata.MCP))
|
||||
if err != nil {
|
||||
return SchemaRegistry{}, fmt.Errorf("encode interface metadata summary: %w", err)
|
||||
}
|
||||
// Derive Agent metadata summary from the assembled ContractFinal /
|
||||
// ProductDecl surface so runtime delivery and cmd_schema_catalog dumps
|
||||
// share one Catalog blob (inject remains validation-only for the dump).
|
||||
|
||||
@@ -17,14 +17,13 @@ import (
|
||||
// These wire structs are used only at the JSON boundary. Once decoded, the
|
||||
// release command keeps and queries SchemaRegistry/SchemaIndex exclusively.
|
||||
type schemaCatalogWire struct {
|
||||
Kind string `json:"kind"`
|
||||
Level string `json:"level"`
|
||||
Source string `json:"source"`
|
||||
Count int `json:"count"`
|
||||
ToolCount int `json:"tool_count"`
|
||||
Products []schemaProductWire `json:"products"`
|
||||
InterfaceMetadata json.RawMessage `json:"interface_metadata"`
|
||||
AgentMetadata json.RawMessage `json:"agent_metadata"`
|
||||
Kind string `json:"kind"`
|
||||
Level string `json:"level"`
|
||||
Source string `json:"source"`
|
||||
Count int `json:"count"`
|
||||
ToolCount int `json:"tool_count"`
|
||||
Products []schemaProductWire `json:"products"`
|
||||
AgentMetadata json.RawMessage `json:"agent_metadata"`
|
||||
}
|
||||
|
||||
type schemaProductWire struct {
|
||||
@@ -193,12 +192,11 @@ func schemaRegistryFromTyped(catalog schemaCatalogWire, tools map[string]schemaT
|
||||
return SchemaRegistry{}, SchemaIndex{}, fmt.Errorf("schema Catalog full tools absent from typed products: %s", strings.Join(missing, ", "))
|
||||
}
|
||||
registry := SchemaRegistry{
|
||||
Kind: catalog.Kind,
|
||||
Level: catalog.Level,
|
||||
Source: catalog.Source,
|
||||
Products: products,
|
||||
InterfaceMetadata: catalog.InterfaceMetadata,
|
||||
AgentMetadata: catalog.AgentMetadata,
|
||||
Kind: catalog.Kind,
|
||||
Level: catalog.Level,
|
||||
Source: catalog.Source,
|
||||
Products: products,
|
||||
AgentMetadata: catalog.AgentMetadata,
|
||||
}
|
||||
index, err := registry.Index()
|
||||
if err != nil {
|
||||
|
||||
@@ -101,7 +101,6 @@ jq -S '
|
||||
]
|
||||
} +
|
||||
(if (($catalog.source // "") | type == "string" and length > 0) then {source: $catalog.source} else {} end) +
|
||||
(if $catalog | has("interface_metadata") then {interface_metadata: $catalog.interface_metadata} else {} end) +
|
||||
(if $catalog | has("agent_metadata") then {agent_metadata: $catalog.agent_metadata} else {} end) +
|
||||
{catalog_hash: $snapshot.source_hash} +
|
||||
(if (($snapshot.surface_hash // "") | nonempty) then {surface_hash: $snapshot.surface_hash} else {} end)
|
||||
|
||||
Reference in New Issue
Block a user