feat(builder): documented launch options only, and no game-specific code
Launch options must be documented. A draft passed an option its server doesn't have; servers ignore unknown options, so it booted and passed every boot test while its setting did nothing. build now reads the pages research based the variant on, in full, and the drafter rejects any launch option in the startup command that none of them, nor the image's own scripts, mention. Shell tools' options (mkdir -p, [ -n ...]) are skipped; the check is off without sources. The builder is game-agnostic: - AUTHORING.md (the model's rules), the research prompt and the schema describe the rules without naming a game. - The draft prompt no longer includes real templates from the repo. Its format example is one invented server (no real command, options, ports or app id), checked by TestExampleTemplateFollowsTheRules. - Comments, help texts, BUILDER.md and test fixtures use invented names and values. - TestBuilderIsGameAgnostic reads every game's name and id from games/ and fails if any appears in the builder's code, tests, rules, schemas or docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dd92b6be4c
commit
8623ba2d7b
16 files changed
+395
-120
No files matched your search
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -75,7 +76,7 @@ func splitSettings(game map[string]any) []string {
|
||||
|
||||
var shellWrap = regexp.MustCompile(`^\s*(?:ba)?sh\s+-c\s+'(.*)'\s*$`)
|
||||
|
||||
// unwrapShell looks inside a startup command that is one bash -c '...' (ARK's), which would otherwise be
|
||||
// unwrapShell looks inside a startup command that is one bash -c '...', which would otherwise be
|
||||
// all single-quoted text.
|
||||
func unwrapShell(cmd string) string {
|
||||
if m := shellWrap.FindStringSubmatch(cmd); m != nil && !strings.Contains(m[1], "'") {
|
||||
@@ -248,3 +249,77 @@ func portNumber(v any) (int, bool) {
|
||||
p, err := strconv.Atoi(strings.TrimSpace(s))
|
||||
return p, err == nil && p > 0 && p < 65536
|
||||
}
|
||||
|
||||
var (
|
||||
optionToken = regexp.MustCompile(`(?:^|[\s("'])(-{1,2}[A-Za-z][A-Za-z0-9_.]*(?:-[A-Za-z0-9_.]+)*)`)
|
||||
segmentSep = regexp.MustCompile(`;|&&|\|\||\||\n`)
|
||||
testOps = map[string]bool{"eq": true, "ne": true, "lt": true, "gt": true, "le": true, "ge": true, "nt": true, "ot": true, "ef": true}
|
||||
// Options of these are the shell's and its tools', not the game's
|
||||
shellTools = map[string]bool{"mkdir": true, "cp": true, "mv": true, "ln": true, "rm": true, "chmod": true, "chown": true,
|
||||
"wget": true, "curl": true, "tar": true, "unzip": true, "test": true, "[": true, "[[": true, "echo": true, "printf": true,
|
||||
"sleep": true, "find": true, "sed": true, "grep": true, "cd": true, "export": true, "touch": true, "bash": true, "sh": true,
|
||||
"cat": true, "head": true, "tail": true, "ls": true, "set": true, "ulimit": true, "env": true, "id": true}
|
||||
)
|
||||
|
||||
// undocumentedOptions finds launch options in the startup command that none of the researched pages (nor
|
||||
// the image's own scripts) mention. Servers silently ignore options they don't know, so a made-up one
|
||||
// boots fine and passes every boot test while its setting does nothing.
|
||||
func undocumentedOptions(game map[string]any, docs string, facts *imageFacts) []string {
|
||||
if strings.TrimSpace(docs) == "" {
|
||||
return nil
|
||||
}
|
||||
startup, _ := game["defaultStartupCommand"].(string)
|
||||
corpus := docs
|
||||
if facts != nil {
|
||||
for _, s := range facts.Scripts {
|
||||
corpus += "\n" + s
|
||||
}
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
var missing []string
|
||||
for _, opt := range launchOptions(unwrapShell(startup)) {
|
||||
name := strings.TrimLeft(opt, "-")
|
||||
key := strings.ToLower(name)
|
||||
if seen[key] {
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
documented := regexp.MustCompile(`(?i)(^|[^A-Za-z0-9_])-{1,2}` + regexp.QuoteMeta(name) + `($|[^A-Za-z0-9_])`)
|
||||
if !documented.MatchString(corpus) {
|
||||
missing = append(missing, opt)
|
||||
}
|
||||
}
|
||||
if len(missing) == 0 {
|
||||
return nil
|
||||
}
|
||||
return []string{fmt.Sprintf("the startup command passes %s, which none of the pages researched for this game mention. "+
|
||||
"Servers silently ignore options they don't know, so it boots fine but does nothing: remove it (and any setting that "+
|
||||
"only feeds it), or spell it exactly as the documentation does", strings.Join(missing, ", "))}
|
||||
}
|
||||
|
||||
// launchOptions lists the -options passed to the game, skipping the shell's own (mkdir -p, [ -n ... ]).
|
||||
func launchOptions(cmd string) []string {
|
||||
var out []string
|
||||
for _, seg := range segmentSep.Split(cmd, -1) {
|
||||
fields := strings.Fields(strings.TrimLeft(strings.TrimSpace(seg), "({"))
|
||||
i := 0
|
||||
for i < len(fields) && (fields[i] == "exec" || fields[i] == "then" || fields[i] == "do" || fields[i] == "else" ||
|
||||
(assignWord.MatchString(fields[i]) && !strings.Contains(fields[i], "=("))) {
|
||||
i++
|
||||
}
|
||||
if i == len(fields) {
|
||||
continue
|
||||
}
|
||||
if word := path.Base(fields[i]); shellTools[word] {
|
||||
continue
|
||||
}
|
||||
for _, m := range optionToken.FindAllStringSubmatch(strings.Join(fields[i:], " "), -1) {
|
||||
name := strings.TrimLeft(m[1], "-")
|
||||
if len(name) < 2 || testOps[name] {
|
||||
continue
|
||||
}
|
||||
out = append(out, m[1])
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user