Files
dingtalk-workspace-cli/scripts/policy/check-generated-drift.sh
T
玉澜 51dc237d8a feat: declarative LeafSpec command framework + schema generation/consumption separation
== LeafSpec command framework (internal/helpers/leaf.go) ==
Declarative command construction: LeafSpec/LeafFlag/NewLeafCommand with
Call (pluggable dispatch), LeafInt, PostMount, Trim, Validate. Collapses
per-command hand-written required validation, alias/env fallback, value
transform, and toolArgs assembly into one declarative path.

== devapp migration (28/31 commands) ==
All MCP-direct devapp leaf commands migrated to LeafSpec. Factories
(devAppCall/devAppCallCursor/devAppMeta) fold 33 repeated closures.
fakeDevAppRunner asserts toolArgs for every migrated command. 4 complex
commands (delete/robot submit/result/config) kept hand-written.

== Schema generation/consumption separation ==
- gen.go: isolated //go:generate pragmas from business code.
- command_meta.go: ResolveMeta(cliPath) -> CommandMeta{Identity,Safety,Selection}.
- command_safety.go: SafetyForCLIPath + RenderSafetyAnnotation; safety metadata
  flows from embedded catalog into --help output.
- calendar.go HelpFunc fix: delegates to root HelpFunc at help-time.
- schema_catalog_structure.go: closed catalog structure validation gate.

== Registry + catalog per-product sharding ==
schema_command_registry and schema_catalog split into per-product shards,
eliminating concurrent-PR merge conflicts on these files.

== MCP metadata refresh tool ==
cmd/fetch_mcp_metadata: iterates 26 MCP server endpoints, merges with previous
data for cross-server interface_ref. make fetch-mcp-metadata target.

== AGENTS.md ==
Documents the generation/consumption split.

Verified: make policy exit 0, drift zero, all tests pass.
2026-07-19 09:38:43 +08:00

94 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
set -eu
# Regenerate deterministic downstream release assets from the reviewed
# CommandRegistry into a temporary directory and compare them with the
# committed files.
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)"
metadata_generator="$exec_tmp/schema-agent-metadata"
catalog_generator="$exec_tmp/schema-catalog"
trap 'rm -rf "$tmp" "$exec_tmp"' EXIT HUP INT TERM
go build -o "$metadata_generator" ./internal/generator/cmd_schema_agent_metadata
go build -a -o "$catalog_generator" ./internal/generator/cmd_schema_catalog
# CommandRegistry is a reviewed input, never a generated artifact. Keep an
# independent byte-for-byte guard around the ordinary downstream generators.
registry_guard="$tmp/schema_command_registry"
cp -R internal/cli/schema_command_registry "$registry_guard"
# Also guard human-authored metadata + selection hint trees.
metadata_guard="$tmp/metadata-hints"
selection_guard="$tmp/selection-hints"
cp -R internal/cli/schema_hints/metadata "$metadata_guard"
cp -R internal/cli/schema_hints/selection "$selection_guard"
metadata_tmp="$tmp/metadata"
audit_tmp="$tmp/audit.json"
catalog_tmp="$tmp/schema_catalog"
catalog_tmp_second="$tmp/schema_catalog-second"
"$metadata_generator" \
-root . \
-registry internal/cli/schema_command_registry \
-output-dir "$metadata_tmp" \
-audit-output "$audit_tmp"
if ! diff -qr internal/cli/schema_agent_metadata "$metadata_tmp" >/dev/null; then
printf '%s\n' 'generated drift: internal/cli/schema_agent_metadata is stale' >&2
printf '%s\n' 'run: make generate-schema' >&2
diff -ru internal/cli/schema_agent_metadata "$metadata_tmp" || true
exit 1
fi
if ! cmp -s internal/cli/schema_agent_metadata_audit.json "$audit_tmp"; then
printf '%s\n' 'generated drift: internal/cli/schema_agent_metadata_audit.json is stale' >&2
printf '%s\n' 'run: make generate-schema' >&2
diff -u internal/cli/schema_agent_metadata_audit.json "$audit_tmp" || true
exit 1
fi
"$catalog_generator" \
-root . \
-output "$catalog_tmp"
"$catalog_generator" \
-root . \
-output "$catalog_tmp_second"
if ! diff -qr internal/cli/schema_command_registry "$registry_guard" >/dev/null; then
printf '%s\n' 'generation modified reviewed input internal/cli/schema_command_registry/' >&2
exit 1
fi
if ! diff -qr internal/cli/schema_hints/metadata "$metadata_guard" >/dev/null; then
printf '%s\n' 'generation modified reviewed input internal/cli/schema_hints/metadata' >&2
exit 1
fi
if ! diff -qr internal/cli/schema_hints/selection "$selection_guard" >/dev/null; then
printf '%s\n' 'generation modified reviewed input internal/cli/schema_hints/selection' >&2
exit 1
fi
if ! diff -qr "$catalog_tmp" "$catalog_tmp_second" >/dev/null; then
printf '%s\n' 'generated drift: consecutive Catalog generations are not byte-identical' >&2
diff -ru "$catalog_tmp" "$catalog_tmp_second" || true
exit 1
fi
if ! diff -qr internal/cli/schema_catalog "$catalog_tmp" >/dev/null; then
printf '%s\n' 'generated drift: internal/cli/schema_catalog is stale' >&2
printf '%s\n' 'run: make generate-schema' >&2
diff -ru internal/cli/schema_catalog "$catalog_tmp" || true
exit 1
fi
printf 'generated drift check: ok\n'