Merge pull request #750 from samcharles93/feat/748-skillcurator-nilerr-finding-at-skillcuratorgo110
skillcurator: nilerr finding at skillcurator.go:110 (archie)
This commit is contained in:
commit
b51fffe235
3 files changed
+42
-12
No files matched your search
@@ -112,11 +112,7 @@ func (c *Curator) reviewOne(ctx context.Context, name string) ([]curator.Action,
|
||||
// batch on a non-nil error, which would stop reviewing every
|
||||
// other skill over one bad file (see skillcurator_test.go's
|
||||
// "must not abort review of the others").
|
||||
return []curator.Action{{ //nolint:nilerr
|
||||
Type: ActionInvalid,
|
||||
Detail: name,
|
||||
Reason: fail.Error(),
|
||||
}}, nil
|
||||
return invalidFinding(name, fail)
|
||||
}
|
||||
|
||||
if missing := missingField(fm); missing != "" {
|
||||
@@ -141,6 +137,16 @@ func (c *Curator) reviewOne(ctx context.Context, name string) ([]curator.Action,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// invalidFinding converts a parse error into a per-skill action. Parse
|
||||
// failures are expected findings, so they must not abort the rest of Pass.
|
||||
func invalidFinding(name string, parseErr error) ([]curator.Action, error) {
|
||||
return []curator.Action{{
|
||||
Type: ActionInvalid,
|
||||
Detail: name,
|
||||
Reason: parseErr.Error(),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// missingField returns the name of the first required frontmatter field
|
||||
// fm lacks, or "" if both are present. Order (name before description)
|
||||
// only affects which single reason is reported when both are missing;
|
||||
|
||||
@@ -60,6 +60,9 @@ func TestPassFlagsAParseFailureWithoutWriting(t *testing.T) {
|
||||
if res.Actions[0].Detail != "broken" {
|
||||
t.Errorf("Detail = %q, want the skill name", res.Actions[0].Detail)
|
||||
}
|
||||
if res.Actions[0].Reason == "" {
|
||||
t.Error("Reason is empty, want the parse failure")
|
||||
}
|
||||
|
||||
// The broken skill must be untouched: this curator never rewrites
|
||||
// content it could not parse.
|
||||
|
||||
@@ -2,13 +2,16 @@ package releaseupdate
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
func TestUpdateInstallGatewayOnlySkipsRuntimeWork(t *testing.T) {
|
||||
@@ -140,9 +143,7 @@ func TestUpdateWatchdogRestoresTaskDatabaseOnDaemonRollback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for path, version := range map[string]int{dbPath: 2, backupPath: 1} {
|
||||
if output, err := exec.CommandContext(t.Context(), "sqlite3", path, fmt.Sprintf("PRAGMA user_version=%d; CREATE TABLE tasks (id INTEGER);", version)).CombinedOutput(); err != nil {
|
||||
t.Fatalf("create database %s: %v: %s", path, err, output)
|
||||
}
|
||||
createSQLiteDatabase(t, path, version)
|
||||
}
|
||||
callsPath := filepath.Join(work, "calls")
|
||||
writeFakeCommand(t, fakeDir, "systemctl", `printf '%s\n' "systemctl $*" >> "$ARCHIE_TEST_CALLS"`)
|
||||
@@ -157,12 +158,17 @@ func TestUpdateWatchdogRestoresTaskDatabaseOnDaemonRollback(t *testing.T) {
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("watchdog failed: %v\n%s", err, output)
|
||||
}
|
||||
output, err := exec.CommandContext(t.Context(), "sqlite3", dbPath, "PRAGMA user_version;").Output()
|
||||
db, err := sql.Open("sqlite", dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.TrimSpace(string(output)) != "1" {
|
||||
t.Fatalf("restored schema version = %q, want 1", output)
|
||||
defer db.Close()
|
||||
var version int
|
||||
if err := db.QueryRow("PRAGMA user_version").Scan(&version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if version != 1 {
|
||||
t.Fatalf("restored schema version = %d, want 1", version)
|
||||
}
|
||||
calls, err := os.ReadFile(callsPath)
|
||||
if err != nil {
|
||||
@@ -189,6 +195,21 @@ func TestUpdateWatchdogRestoresTaskDatabaseOnDaemonRollback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func createSQLiteDatabase(t *testing.T, path string, version int) {
|
||||
t.Helper()
|
||||
db, err := sql.Open("sqlite", path)
|
||||
if err != nil {
|
||||
t.Fatalf("open database %s: %v", path, err)
|
||||
}
|
||||
defer db.Close()
|
||||
if _, err := db.Exec("PRAGMA user_version = " + strconv.Itoa(version)); err != nil {
|
||||
t.Fatalf("set database version for %s: %v", path, err)
|
||||
}
|
||||
if _, err := db.Exec("CREATE TABLE tasks (id INTEGER)"); err != nil {
|
||||
t.Fatalf("create tasks table in %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func runUpdateInstallScript(t *testing.T, environment map[string]string) (Result, []string) {
|
||||
t.Helper()
|
||||
ctx := t.Context()
|
||||
|
||||
Reference in new issue
Block a user