Skip to content

[Config] Make AST-only config loading fail closed for unsupported Go expressions and unknown fields #714

Description

@cssbruno

Priority

High — configuration correctness, trust-boundary clarity, and prevention of silent build/default changes.

Context

internal/project has an AST-only loader for gowdk.config.go. It parses Go syntax and then manually interprets a subset of gowdk.Config without type-checking the file.

The current decoder is permissive in places that should be fail-closed:

  • selector expressions are treated as not requiring executable evaluation;
  • nested config parsers usually ignore unknown fields;
  • non-keyed composite literal elements are skipped by the non-strict parser;
  • unsupported literals often become zero values instead of diagnostics.

This is related to the broader loader unification tracked in #665, but this issue is a focused correctness bug that should be fixed even before the final config model is chosen.

Problem

A configuration that normal Go compilation would reject or evaluate correctly can be silently loaded with different values.

Example shape:

var Config = gowdk.Config{
    AppName: constants.Name,
    Source: gowdk.SourceConfig{
        Incldue: []string{"src/**/*.gwdk"},
    },
}

Observed-by-inspection risks:

  1. constants.Name is a selector expression, so it is classified as static, but the string parser cannot decode it and returns "".
  2. Incldue is not a valid gowdk.SourceConfig field, but nested parsing ignores it, leaving Source.Include empty.
  3. Unkeyed nested values can also be skipped rather than rejected.

This makes small refactors or typos change the effective build configuration without an actionable diagnostic.

Proposed direction

Until the config loader is unified:

  • type-check gowdk.config.go before accepting the AST-only path;
  • require keyed struct literals for all decoded config structs;
  • reject every unknown nested config field;
  • reject non-literal values unless the loader deliberately falls back to executable evaluation;
  • report the field path, for example Config.Source.Include;
  • do not let unsupported values silently decode as zero values.

Acceptance criteria

  • Config and every nested config literal reject unknown fields.
  • Unkeyed config literals are rejected or consistently delegated to executable loading.
  • Selector expressions such as constants do not silently decode as zero values.
  • Unsupported values produce diagnostics with a field path.
  • Normal Go type errors in gowdk.config.go are surfaced before AST decoding succeeds.
  • Tests cover constants, selector expressions, misspelled nested fields, unkeyed literals, duplicate fields, aliases, and unsupported expressions.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions