Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions cmd/foxtrack-bridge/config_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func transferConfig() *config.Config {
func secretConfig() *config.Config {
cfg := transferConfig()
cfg.APIKey, cfg.FoxTrack2APIKey = "SECRET-legacy-key", "SECRET-ft2-key"
cfg.Printers[0].ID, cfg.Printers[1].ID = "id-monsieur", "id-sherlock"
cfg.Printers[0].ID, cfg.Printers[1].ID = "id-test-printer-a", "id-test-printer-b"
cfg.Printers[0].LANCode = "SECRET-lan-1"
cfg.Printers[1].LANCode = "SECRET-lan-2"
cfg.Printers = append(cfg.Printers,
Expand Down Expand Up @@ -220,13 +220,13 @@ func TestExportableConfig_HoldsNoSecret(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for _, leaked := range []string{"SECRET", "sk-secret", "cloud-token", "81f1aafd", "f849c383", "ft-key"} {
for _, leaked := range []string{"SECRET", "sk-secret", "cloud-token", "12345678", "23456789", "ft-key"} {
if strings.Contains(string(data), leaked) {
t.Errorf("export holds %q: %s", leaked, data)
}
}
// What is not secret stays, so a restore brings the printers back.
if out.Printers[0].Name != "Monsieur" || out.Printers[0].Serial != "01P00C580801716" || out.Printers[2].Plug.DeviceID != "dev1" ||
if out.Printers[0].Name != "Test Printer A" || out.Printers[0].Serial != "01P00TEST0000A1" || out.Printers[2].Plug.DeviceID != "dev1" ||
out.Notifications.Channels[0].Target != "123" || out.MQTTExport.Broker != "tcp://broker:1883" {
t.Fatalf("export lost settings that are not secret: %s", data)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestResolveConfigImport_KeepsAccountSecretsAndRefusesClear(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(got.Printers) != 2 || got.Printers[1].LANCode != "f849c383" {
if len(got.Printers) != 2 || got.Printers[1].LANCode != "23456789" {
t.Fatalf("printers = %+v", got.Printers)
}
if got.Security != old.Security || got.BambuCloud != old.BambuCloud {
Expand Down Expand Up @@ -409,7 +409,7 @@ func TestConfigExportImportHandlers(t *testing.T) {
t.Fatalf("Content-Disposition = %q", cd)
}
body := rec.Body.String()
for _, leaked := range []string{"cloud-token", "sk-secret", `"security"`, "ft-key", "81f1aafd", "f849c383"} {
for _, leaked := range []string{"cloud-token", "sk-secret", `"security"`, "ft-key", "12345678", "23456789"} {
if strings.Contains(body, leaked) {
t.Fatalf("export leaked %q", leaked)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/foxtrack-bridge/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ func TestBambuCertSerial(t *testing.T) {
cert := func(issuerOrg, cn string) *x509.Certificate {
return &x509.Certificate{Issuer: pkix.Name{Organization: []string{issuerOrg}}, Subject: pkix.Name{CommonName: cn}}
}
if s, ok := bambuCertSerial(cert("BBL Technologies Co., Ltd", "01P00C580801716")); !ok || s != "01P00C580801716" || bambuSerialModel(s) != "P1S" {
if s, ok := bambuCertSerial(cert("BBL Technologies Co., Ltd", "01P00TEST0000A1")); !ok || s != "01P00TEST0000A1" || bambuSerialModel(s) != "P1S" {
t.Errorf("Bambu cert: got %q, %v", s, ok)
}
if s, ok := bambuCertSerial(cert("Mosquitto", "01P00C580801716")); ok {
if s, ok := bambuCertSerial(cert("Mosquitto", "01P00TEST0000A1")); ok {
t.Errorf("accepted a non-Bambu broker: %q", s)
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/foxtrack-bridge/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func withQueue(t *testing.T) {
configMutex.Lock()
saved := configStore
configStore = &config.Config{Printers: []config.Printer{
{ID: "p1", Name: "Monsieur", MoonrakerURL: "http://192.168.1.6:7125"},
{ID: "p2", Name: "Sherlock", MoonrakerURL: "http://192.168.1.7:7125"},
{ID: "p1", Name: "Test Printer A", MoonrakerURL: "http://192.0.2.6:7125"},
{ID: "p2", Name: "Test Printer B", MoonrakerURL: "http://192.0.2.7:7125"},
{ID: "p3", Name: "Prusa", PrusaLinkURL: "http://192.168.1.8"},
}}
configMutex.Unlock()
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestQueue_StartNext(t *testing.T) {
t.Fatalf("a failed start must keep the file queued: %s", names(q["p1"]))
}
it, err := queueStartNext("p1", ok, start)
if err != nil || it.FileName != "a.3mf" || started[0] != "Monsieur:a.3mf" {
if err != nil || it.FileName != "a.3mf" || started[0] != "Test Printer A:a.3mf" {
t.Fatalf("start: %v %+v %v", err, it, started)
}
if q := queueSnapshot(); names(q["p1"]) != "b.3mf" {
Expand Down Expand Up @@ -205,7 +205,7 @@ func readSavedQueues(t *testing.T) (string, map[string][]queueItem) {
func TestQueue_SaveDropsRemovedPrinters(t *testing.T) {
withQueue(t)
configMutex.Lock()
configStore.Printers = []config.Printer{{ID: "p1", Name: "Monsieur"}}
configStore.Printers = []config.Printer{{ID: "p1", Name: "Test Printer A"}}
configMutex.Unlock()
printQueue.Lock()
printQueue.loaded = true
Expand Down
6 changes: 3 additions & 3 deletions cmd/foxtrack-bridge/review_fixes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import (
// can never connect: the edit is refused instead.
func TestApplyPrinterEdit_BambuSerialChangeNeedsAccessCode(t *testing.T) {
old := editFixture()
_, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01P00C580809999"), LANCode: strp("")}, notBusy)
_, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01P00TEST0000E5"), LANCode: strp("")}, notBusy)
if !errors.Is(err, errInvalidPrinterEdit) {
t.Fatalf("err = %v, want errInvalidPrinterEdit", err)
}
if want := "Enter the access code again when you change the serial number."; err.Error() != want {
t.Fatalf("message = %q, want %q", err.Error(), want)
}
// Typing the code again, or leaving the serial alone, is fine.
got, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01P00C580809999"), LANCode: strp("newcode1")}, notBusy)
got, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01P00TEST0000E5"), LANCode: strp("newcode1")}, notBusy)
if err != nil || got.Printers[0].LANCode != "newcode1" {
t.Fatalf("new serial with a code: err = %v", err)
}
if _, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01p00c580801716")}, notBusy); err != nil {
if _, _, err := applyPrinterEdit(old, "a", printerEdit{Serial: strp("01p00test0000a1")}, notBusy); err != nil {
t.Fatalf("same serial in another case: err = %v, want nil", err)
}
}
Expand Down
40 changes: 20 additions & 20 deletions cmd/foxtrack-bridge/server_ai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func jsonPost(path, body string) *http.Request {

func aiPrinters() []config.Printer {
return []config.Printer{
{ID: "p1", Name: "Monsieur", IP: "192.168.87.22", Serial: "01P00C580801716", LANCode: "81f1aafd"},
{ID: "p2", Name: "Sherlock", MoonrakerURL: "http://192.168.87.30:7125"},
{ID: "p1", Name: "Test Printer A", IP: "192.0.2.22", Serial: "01P00TEST0000A1", LANCode: "12345678"},
{ID: "p2", Name: "Test Printer B", MoonrakerURL: "http://192.0.2.30:7125"},
}
}

Expand Down Expand Up @@ -442,11 +442,11 @@ func TestExecuteAITool_ListPrintersReportsKind(t *testing.T) {
row := r.(map[string]any)
kinds[row["name"].(string)] = row["kind"].(string)
}
if kinds["Monsieur"] != "bambu-lan" {
t.Errorf("Monsieur kind = %q, want bambu-lan", kinds["Monsieur"])
if kinds["Test Printer A"] != "bambu-lan" {
t.Errorf("Test Printer A kind = %q, want bambu-lan", kinds["Test Printer A"])
}
if kinds["Sherlock"] != "klipper" {
t.Errorf("Sherlock kind = %q, want klipper", kinds["Sherlock"])
if kinds["Test Printer B"] != "klipper" {
t.Errorf("Test Printer B kind = %q, want klipper", kinds["Test Printer B"])
}
}

Expand All @@ -457,11 +457,11 @@ func TestExecuteAITool_DisconnectedPrinterIsAConnectionError(t *testing.T) {
configMutex.Lock()
configStore = &config.Config{Printers: aiPrinters()}
configMutex.Unlock()
const httpErr = `Get "http://192.168.87.30:7125/printer/objects/query": context deadline exceeded`
mqttpkg.UpdatePrinterState("Sherlock", mqttpkg.TelemetryData{Status: "disconnected", Error: httpErr})
defer mqttpkg.ResetPrinterStateForTest("Sherlock")
const httpErr = `Get "http://192.0.2.30:7125/printer/objects/query": context deadline exceeded`
mqttpkg.UpdatePrinterState("Test Printer B", mqttpkg.TelemetryData{Status: "disconnected", Error: httpErr})
defer mqttpkg.ResetPrinterStateForTest("Test Printer B")

got := toolValue(t, "get_printer_status", `{"printer_name":"Sherlock"}`)
got := toolValue(t, "get_printer_status", `{"printer_name":"Test Printer B"}`)
if got["reporting"] != false {
t.Errorf("reporting = %v, want false", got["reporting"])
}
Expand All @@ -478,8 +478,8 @@ func TestExecuteAITool_DisconnectedPrinterIsAConnectionError(t *testing.T) {
list := toolValue(t, "list_printers", `{}`)
for _, r := range list["printers"].([]any) {
row := r.(map[string]any)
if row["name"] == "Sherlock" && row["reporting"] != false {
t.Errorf("list_printers: Sherlock reporting = %v, want false", row["reporting"])
if row["name"] == "Test Printer B" && row["reporting"] != false {
t.Errorf("list_printers: Test Printer B reporting = %v, want false", row["reporting"])
}
}
}
Expand All @@ -491,7 +491,7 @@ func TestExecuteAITool_CameraRefusedWhenNotAllowed(t *testing.T) {
configStore = &config.Config{Printers: aiPrinters(), AI: &config.AI{Enabled: true, AllowCamera: false}}
configMutex.Unlock()

got := toolValue(t, "view_printer_camera", `{"printer_name":"Monsieur"}`)
got := toolValue(t, "view_printer_camera", `{"printer_name":"Test Printer A"}`)
if got["error"] != "not_permitted" {
t.Errorf("error = %v, want not_permitted", got["error"])
}
Expand All @@ -506,14 +506,14 @@ func TestExecuteAITool_CameraHiddenIsNoCamera(t *testing.T) {
configStore = &config.Config{Printers: printers, AI: &config.AI{Enabled: true, AllowCamera: true}}
configMutex.Unlock()

got := toolValue(t, "view_printer_camera", `{"printer_name":"Monsieur"}`)
got := toolValue(t, "view_printer_camera", `{"printer_name":"Test Printer A"}`)
if got["error"] != "no_camera" {
t.Errorf("error = %v, want no_camera", got["error"])
}
list := toolValue(t, "list_printers", `{}`)
for _, r := range list["printers"].([]any) {
row := r.(map[string]any)
if row["name"] == "Monsieur" && row["camera_available"] != false {
if row["name"] == "Test Printer A" && row["camera_available"] != false {
t.Errorf("hidden camera: camera_available = %v, want false", row["camera_available"])
}
}
Expand Down Expand Up @@ -569,14 +569,14 @@ func TestToolRecentLogs_RedactsStoredSecrets(t *testing.T) {
configMutex.Lock()
configStore = &config.Config{
APIKey: "fox-token-abcdef",
Printers: []config.Printer{{Name: "Monsieur", LANCode: "81f1aafd"}},
Printers: []config.Printer{{Name: "Test Printer A", LANCode: "12345678"}},
AI: &config.AI{APIKey: "sk-provider-key-1234"},
}
configMutex.Unlock()

logBufMu.Lock()
logBuf = []string{
"[Monsieur] connect failed with code 81f1aafd",
"[Test Printer A] connect failed with code 12345678",
"[relay] rejected token fox-token-abcdef",
"[assistant] provider key sk-provider-key-1234 refused",
}
Expand All @@ -589,7 +589,7 @@ func TestToolRecentLogs_RedactsStoredSecrets(t *testing.T) {

got := toolRecentLogs("", 40)
encoded, _ := json.Marshal(got)
for _, secret := range []string{"81f1aafd", "fox-token-abcdef", "sk-provider-key-1234"} {
for _, secret := range []string{"12345678", "fox-token-abcdef", "sk-provider-key-1234"} {
if strings.Contains(string(encoded), secret) {
t.Errorf("log output leaked %q: %s", secret, encoded)
}
Expand All @@ -605,15 +605,15 @@ func TestToolRecentLogs_FiltersByPrinter(t *testing.T) {
configMutex.Unlock()

logBufMu.Lock()
logBuf = []string{"[Monsieur] hello", "[Sherlock] hello", "[Monsieur] again"}
logBuf = []string{"[Test Printer A] hello", "[Test Printer B] hello", "[Test Printer A] again"}
logBufMu.Unlock()
t.Cleanup(func() {
logBufMu.Lock()
logBuf = nil
logBufMu.Unlock()
})

got := toolRecentLogs("Monsieur", 40)
got := toolRecentLogs("Test Printer A", 40)
lines := got["lines"].([]string)
if len(lines) != 2 {
t.Fatalf("lines = %d, want 2: %v", len(lines), lines)
Expand Down
26 changes: 13 additions & 13 deletions cmd/foxtrack-bridge/server_config_guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

func twoPrinters() []config.Printer {
return []config.Printer{
{Name: "Monsieur", IP: "192.168.87.22", Serial: "01P00C580801716", LANCode: "81f1aafd"},
{Name: "Sherlock", IP: "192.168.87.24", Serial: "01P00C580800360", LANCode: "f849c383"},
{Name: "Test Printer A", IP: "192.0.2.22", Serial: "01P00TEST0000A1", LANCode: "12345678"},
{Name: "Test Printer B", IP: "192.0.2.24", Serial: "01P00TEST0000B2", LANCode: "23456789"},
}
}

Expand Down Expand Up @@ -97,12 +97,12 @@ func TestResolveConfigUpdate_EmptyPrintersOKWhenExistingEmpty(t *testing.T) {
// Backward compat: old-shape payload with a non-empty array replaces as before.
func TestResolveConfigUpdate_NonEmptyReplaceBackwardCompat(t *testing.T) {
old := &config.Config{Printers: twoPrinters()}
got, err := resolveConfigUpdate(old, []byte(`{"printers":[{"name":"Watson","ip":"192.168.87.26","serial":"01P00C591701791","lan_code":"f065d489"}]}`))
got, err := resolveConfigUpdate(old, []byte(`{"printers":[{"name":"Test Printer C","ip":"192.0.2.26","serial":"01P00TEST0000C3","lan_code":"34567890"}]}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(got.Printers) != 1 || got.Printers[0].Name != "Watson" {
t.Fatalf("printers = %+v, want single Watson", got.Printers)
if len(got.Printers) != 1 || got.Printers[0].Name != "Test Printer C" {
t.Fatalf("printers = %+v, want single Test Printer C", got.Printers)
}
}

Expand All @@ -116,7 +116,7 @@ func TestResolveConfigUpdate_PreservesSecretsOnPartial(t *testing.T) {
if got.APIKey != "stored" {
t.Errorf("api_key = %q, want stored (blank keeps existing)", got.APIKey)
}
if len(got.Printers) != 2 || got.Printers[0].LANCode != "81f1aafd" {
if len(got.Printers) != 2 || got.Printers[0].LANCode != "12345678" {
t.Errorf("printer secrets not preserved: %+v", got.Printers)
}
}
Expand Down Expand Up @@ -295,21 +295,21 @@ func TestResolveConfigUpdate_FullReplaceRejectsNewlyIntroducedDuplicateName(t *t
// the name on disk.
func TestApplyStoredSecrets_SurvivesRename(t *testing.T) {
old := &config.Config{Printers: []config.Printer{
{ID: "printer-1", Name: "Monsieur", IP: "192.168.87.22", Serial: "01P00C580801716", LANCode: "81f1aafd"},
{ID: "printer-1", Name: "Test Printer A", IP: "192.0.2.22", Serial: "01P00TEST0000A1", LANCode: "12345678"},
}}
got, err := resolveConfigUpdate(old, []byte(`{"printers":[
{"id":"printer-1","name":"Monsieur Renamed","ip":"192.168.87.22","serial":"01P00C580801716"}
{"id":"printer-1","name":"Test Printer A Renamed","ip":"192.0.2.22","serial":"01P00TEST0000A1"}
]}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(got.Printers) != 1 {
t.Fatalf("printers = %d, want 1", len(got.Printers))
}
if got.Printers[0].Name != "Monsieur Renamed" {
if got.Printers[0].Name != "Test Printer A Renamed" {
t.Fatalf("Name = %q, want the renamed value", got.Printers[0].Name)
}
if got.Printers[0].LANCode != "81f1aafd" {
if got.Printers[0].LANCode != "12345678" {
t.Fatalf("LANCode = %q, want the stored secret to survive the rename", got.Printers[0].LANCode)
}
if got.Printers[0].ID != "printer-1" {
Expand Down Expand Up @@ -356,11 +356,11 @@ func TestHandlePrinters_POST_AssignsID(t *testing.T) {
// don't have one yet.
func TestResolveConfigUpdate_FullReplaceAssignsMissingIDsOnly(t *testing.T) {
old := &config.Config{Printers: []config.Printer{
{ID: "existing-id", Name: "Monsieur", IP: "192.168.87.22", Serial: "01P00C580801716", LANCode: "81f1aafd"},
{ID: "existing-id", Name: "Test Printer A", IP: "192.0.2.22", Serial: "01P00TEST0000A1", LANCode: "12345678"},
}}
got, err := resolveConfigUpdate(old, []byte(`{"printers":[
{"id":"existing-id","name":"Monsieur","ip":"192.168.87.22","serial":"01P00C580801716","lan_code":"81f1aafd"},
{"name":"Watson","moonraker_url":"http://127.0.0.1:1/"}
{"id":"existing-id","name":"Test Printer A","ip":"192.0.2.22","serial":"01P00TEST0000A1","lan_code":"12345678"},
{"name":"Test Printer C","moonraker_url":"http://127.0.0.1:1/"}
]}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/foxtrack-bridge/server_plug_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestPlugCommand_BambuCloudPrinter(t *testing.T) {
}))
defer srv.Close()

const name, serial = "Madame-cloud-plug-test", "01P00CLOUDPLUG"
const name, serial = "Test Printer D-cloud-plug-test", "01P00CLOUDPLUG"
printers := []config.Printer{{
ID: "p-cloud", Name: name, Serial: serial, Connection: "cloud",
Plug: &config.Plug{Kind: "shelly", Address: strings.TrimPrefix(srv.URL, "http://")},
Expand Down
Loading