返回 DeepSeek-Reasonix
host_contract_test.go
根目录 / desktop / host_contract_test.go
1 package main
2
3 import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "testing"
8 )
9
10 const generatedContractDir = "frontend/src/generated"
11
12 func TestHostContractGeneratedFilesAreCurrent(t *testing.T) {
13 dir := t.TempDir()
14 if err := emitContract(dir); err != nil {
15 t.Fatalf("emit contract: %v", err)
16 }
17 for _, name := range []string{contractTSFile, contractJSONFile} {
18 want, err := os.ReadFile(filepath.Join(dir, name))
19 if err != nil {
20 t.Fatal(err)
21 }
22 got, err := os.ReadFile(filepath.Join(generatedContractDir, name))
23 if err != nil {
24 t.Fatalf("%v\nregenerate with: cd desktop && go run . -emit-contract %s", err, generatedContractDir)
25 }
26 if !bytes.Equal(got, want) {
27 t.Fatalf("%s/%s is stale; regenerate with: cd desktop && go run . -emit-contract %s", generatedContractDir, name, generatedContractDir)
28 }
29 }
30 }
31
32 func TestHostContractFlagParsing(t *testing.T) {
33 for _, tc := range []struct {
34 args []string
35 dir string
36 ok bool
37 }{
38 {[]string{"-emit-contract", "out"}, "out", true},
39 {[]string{"--emit-contract", "out"}, "out", true},
40 {[]string{"-emit-contract=out/dir"}, "out/dir", true},
41 {[]string{"-emit-contract"}, "", false},
42 {[]string{"--host-rpc"}, "", false},
43 } {
44 dir, ok := emitContractDir(tc.args)
45 if dir != tc.dir || ok != tc.ok {
46 t.Errorf("emitContractDir(%v) = %q, %v; want %q, %v", tc.args, dir, ok, tc.dir, tc.ok)
47 }
48 }
49 if !hostRPCRequested([]string{"launch", "--host-rpc"}) || hostRPCRequested([]string{"--safe-mode"}) {
50 t.Fatal("hostRPCRequested must match the exact --host-rpc flag")
51 }
52 }
53
53 lines GO