Files
dingtalk-workspace-cli/scripts/policy/check-generated-drift.sh
玉澜 b1cefba808 refactor(schema): retire reviewed registry; collector is the single identity source
Phase 3 of identity-deregistry. BuildEffectiveCommandRegistry now builds the
EffectiveCommandRegistry from CollectIdentitySpecs(root) instead of the
embedded reviewed registry, and the registry source is removed atomically:

- delete internal/cli/schema_command_registry/ (registry.json + products/),
  schema_command_registry.schema.json, the three //go:embed directives, and
  the registry-only loaders/validators (loadReviewedCommandRegistry,
  decodeCommandRegistry, ValidateCommandRegistrySource, shard assemble/merge
  helpers, ReviewedCommandRegistryMergedJSON/SourceHash, ReviewedCommandSpecs)
- keep CommandSpec/CommandRegistry/EffectiveCommandRegistry,
  newEffectiveCommandRegistry/indexCommandSpecs, and SourceHash; the
  collector-built effective hash is byte-identical to the reviewed one, so
  catalog surface_hash/source_hash are unchanged
- convert the Phase 2 dual-run gate into TestCollectedIdentityIsValidSingleSource:
  collected specs non-empty, no missing primaries, effective build succeeds,
  SourceHash stable across repeated collection walks
- generators: catalog -surface and agent-metadata -registry/-surface become
  fail-closed retired valves; outputguard no longer protects the registry
  paths; fetch_mcp_metadata derives interface refs from collected identity
  instead of the merged registry JSON
- retire scripts/policy/check-schema-command-registry.sh and its Makefile
  invocation; generate-schema/check-generated-drift now fail closed if
  schema_command_registry/ reappears
- update AGENTS.md, docs/reference.md, and in-code reviewed-input notes
2026-08-03 16:18:20 +08:00

86 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
set -eu
# Drift policy after Catalog generator retirement as a committed delivery step:
# 1. param_aliases_generated.go matches a fresh generation (still committed)
# 2. Schema assembly is deterministic (check-schema-assembly.sh)
# 3. Reviewed inputs are not mutated; retired delivery artifacts stay absent
#
# Production delivers Schema exclusively through runtime assembly:
# RegisterSchemaSourceRoot → ResolveSchemaBuild. Catalog and meta-index dumps
# are CI/local artifacts and must never be committed under internal/cli.
ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)"
cd "$ROOT"
. "$ROOT/scripts/policy/policy-runtime.sh"
policy_prepare_runtime "$ROOT"
tmp="$(mktemp -d)"
exec_tmp="$(policy_runtime_mktemp_dir dws-generated-drift)"
param_aliases_generator="$exec_tmp/param-aliases"
trap 'rm -rf "$tmp" "$exec_tmp"' EXIT HUP INT TERM
go build -o "$param_aliases_generator" ./internal/generator/cmd_param_aliases
concepts_guard="$tmp/param_concepts.json"
concepts_schema_guard="$tmp/param_concepts.schema.json"
cp internal/cli/param_concepts.json "$concepts_guard"
cp internal/cli/param_concepts.schema.json "$concepts_schema_guard"
param_aliases_tmp="$tmp/param_aliases_generated.go"
param_aliases_tmp_second="$tmp/param_aliases_generated-second.go"
if [ -e internal/cli/schema_agent_metadata ] || [ -e internal/cli/schema_agent_metadata_audit.json ]; then
printf '%s\n' 'generated drift: retired schema_agent_metadata delivery artifact is present' >&2
printf '%s\n' 'remove internal/cli/schema_agent_metadata/ and schema_agent_metadata_audit.json' >&2
exit 1
fi
"$param_aliases_generator" -root . -output "$param_aliases_tmp"
"$param_aliases_generator" -root . -output "$param_aliases_tmp_second"
if [ -e internal/cli/schema_command_registry ]; then
printf '%s\n' 'generated drift: retired schema_command_registry/ must not be present' >&2
exit 1
fi
if ! cmp -s internal/cli/param_concepts.json "$concepts_guard"; then
printf '%s\n' 'generation modified reviewed input internal/cli/param_concepts.json' >&2
exit 1
fi
if ! cmp -s internal/cli/param_concepts.schema.json "$concepts_schema_guard"; then
printf '%s\n' 'generation modified reviewed input internal/cli/param_concepts.schema.json' >&2
exit 1
fi
if [ -e internal/cli/schema_hints ]; then
printf '%s\n' 'generated drift: retired schema_hints/ must not be present' >&2
exit 1
fi
if [ -e internal/cli/schema_catalog ] ||
[ -e internal/cli/schema_meta_index.gob ] ||
[ -e internal/cli/schema_meta_index.json ]; then
printf '%s\n' 'generated drift: committed Schema Catalog/meta-index fixtures must not be present' >&2
printf '%s\n' 'remove internal/cli/schema_catalog, schema_meta_index.gob, and schema_meta_index.json (ResolveMeta projects from runtime assembly)' >&2
exit 1
fi
if ! cmp -s "$param_aliases_tmp" "$param_aliases_tmp_second"; then
printf '%s\n' 'generated drift: consecutive parameter-alias generations are not byte-identical' >&2
diff -u "$param_aliases_tmp" "$param_aliases_tmp_second" || true
exit 1
fi
if ! cmp -s internal/cli/param_aliases_generated.go "$param_aliases_tmp"; then
printf '%s\n' 'generated drift: internal/cli/param_aliases_generated.go is stale' >&2
printf '%s\n' 'run: make generate-schema' >&2
diff -u internal/cli/param_aliases_generated.go "$param_aliases_tmp" || true
exit 1
fi
# Assembly determinism validates fresh CI/local Catalog dumps.
"$ROOT/scripts/policy/check-schema-assembly.sh"
printf 'generated drift check: ok\n'