Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ repos:
EOF

cat > "${CONFIG_DIR}/templates/shim-workflow-call.yaml" <<'EOF'
# This file is managed by fullsend. Do not edit it directly.
# Upstream: https://github.com/fullsend-ai/fullsend/blob/main/internal/scaffold/fullsend-repo/templates/shim-workflow-call.yaml
# --- fullsend managed below - do not edit ---
fresh shim template
EOF
Expand Down
8 changes: 8 additions & 0 deletions internal/scaffold/fullsend-repo/scripts/reconcile-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ shim_with_header_b64() {
local header
header=$(printf '%s\n' "$remote_raw" | extract_user_header)

# Strip provenance headers that the template now includes natively.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] scope-divergence

The new logic strips provenance headers from user content because the template now includes them natively. This stripping logic is a workaround for the architectural violation. If the template remained header-free per ADR 43, this complexity would be unnecessary.

Suggested fix: Remove the provenance-stripping logic. Instead, ensure reconcile-repos.sh calls PrependManagedHeader (or equivalent header injection) when building the final deployed content.

# Only genuinely user-added content (e.g. license headers) is preserved.
if [ -n "$header" ]; then
header=$(printf '%s\n' "$header" | grep -v '^# This file is managed by fullsend\.' | grep -v '^# Upstream: ' || true)
# Remove leading/trailing blank lines left after stripping.
header=$(printf '%s' "$header" | sed '/./,$!d' | sed -e :a -e '/^[[:space:]]*$/{ $d; N; ba; }')
fi

# Reject non-comment YAML that could inject keys (injection guard first,
# then blank-only check — order matters so the warning fires on injected content).
if [ -n "$header" ] && printf '%s\n' "$header" | grep -qvE '^[[:space:]]*(#|$)'; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is managed by fullsend. Do not edit it directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[high] architectural-divergence

Embedding provenance headers directly in the template contradicts ADR 43's explicit design decision. ADR 43 states: 'The upstream scaffold source files remain header-free so that agents editing templates are not confused by self-referential headers' and 'Header injection is invisible to the scaffold source tree, keeping the embedded templates clean for direct editing and testing.' The template should remain header-free, with headers added only at install/deploy time by PrependManagedHeader.

Suggested fix: Revert the template to header-free state. Fix the reconciliation drift issue by ensuring reconcile-repos.sh applies PrependManagedHeader when comparing or deploying the shim, rather than embedding headers in the template. The idempotent PrependManagedHeader change is correct and should be kept, but applied consistently at deploy time.

# Upstream: https://github.com/fullsend-ai/fullsend/blob/main/internal/scaffold/fullsend-repo/templates/shim-workflow-call.yaml
---
# --- fullsend managed below - do not edit ---
# lint-workflow-size: max-lines=280
Expand Down
7 changes: 6 additions & 1 deletion internal/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,18 @@ func ManagedHeader(path string) string {

// PrependManagedHeader prepends the managed-by header to file content.
// If the file starts with a shebang (#!), the header is inserted after
// the first line. Returns content unchanged if no header applies.
// the first line. Returns content unchanged if no header applies or if
// the header is already present (idempotent).
func PrependManagedHeader(path string, content []byte) []byte {
header := ManagedHeader(path)
if header == "" {
return content
}
s := string(content)
// Skip if the header is already present (template files may embed it).
if strings.HasPrefix(s, header) {
return content
}
if strings.HasPrefix(s, "#!") {
if idx := strings.IndexByte(s, '\n'); idx >= 0 {
return []byte(s[:idx+1] + header + s[idx+1:])
Expand Down
29 changes: 24 additions & 5 deletions internal/scaffold/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ func TestShimWorkflowCallTemplateContent(t *testing.T) {
content, err := FullsendRepoFile("templates/shim-workflow-call.yaml")
require.NoError(t, err)
s := string(content)
// yamllint document-start rule requires --- at the top
assert.True(t, strings.HasPrefix(s, "---\n"), "shim workflow must start with YAML document start marker")
// Template embeds provenance headers; YAML document start marker follows.
assert.True(t, strings.HasPrefix(s, "# This file is managed by fullsend."),
"shim workflow must start with managed-by provenance header")
assert.Contains(t, s, "---\n# --- fullsend managed below - do not edit ---")
// ADR 34: shim has 2 jobs (dispatch + stop-fix), not per-stage jobs
assert.Contains(t, s, "dispatch:")
assert.Contains(t, s, "stop-fix:")
Expand Down Expand Up @@ -884,14 +886,19 @@ func TestPrioritizeHarnessContent(t *testing.T) {

func TestAllScaffoldYAMLDocumentStartMarker(t *testing.T) {
// yamllint document-start rule requires --- at the top of every YAML file.
// Walk embedded scaffold YAML/YML files and verify each starts with "---\n".
// Walk embedded scaffold YAML/YML files and verify each starts with "---\n"
// or with a comment-only provenance header followed by "---\n".
var checked int
err := WalkFullsendRepoAll(func(path string, content []byte) error {
if !strings.HasSuffix(path, ".yaml") && !strings.HasSuffix(path, ".yml") {
return nil
}
assert.True(t, strings.HasPrefix(string(content), "---\n"),
"%s must start with YAML document start marker (---)", path)
s := string(content)
hasDirect := strings.HasPrefix(s, "---\n")
hasAfterHeader := strings.Contains(s, "\n---\n") &&
strings.HasPrefix(s, "# ")
assert.True(t, hasDirect || hasAfterHeader,
"%s must start with YAML document start marker (---) or comment header followed by ---", path)
checked++
return nil
})
Expand Down Expand Up @@ -949,6 +956,18 @@ func TestPrependManagedHeaderNoHeader(t *testing.T) {
assert.Equal(t, content, result, "files without headers should be returned unchanged")
}

func TestPrependManagedHeaderIdempotent(t *testing.T) {
// When the content already starts with the managed header (e.g. a
// template that embeds its own provenance lines), PrependManagedHeader
// must not duplicate it.
header := ManagedHeader("templates/shim-workflow-call.yaml")
require.NotEmpty(t, header)

content := []byte(header + "---\n# --- fullsend managed below - do not edit ---\nname: fullsend\n")
result := PrependManagedHeader("templates/shim-workflow-call.yaml", content)
assert.Equal(t, content, result, "header already present — should be returned unchanged")
}

func TestValidateTriageDeleted(t *testing.T) {
_, err := FullsendRepoFile("scripts/validate-triage.sh")
assert.Error(t, err, "validate-triage.sh should have been deleted")
Expand Down
Loading