diff --git a/go/client_test.go b/go/client_test.go index 64e4629..1de808f 100644 --- a/go/client_test.go +++ b/go/client_test.go @@ -239,17 +239,28 @@ func TestScriptFile(t *testing.T) { socketPath, stop, _ := startTestDaemon(t) defer stop() - cmd := exec.Command(os.Args[0], "--socket", socketPath, "testdata/compute.jl") - cmd.Env = append(os.Environ(), "TEST_CLI=1") - out, err := cmd.Output() - stderr := "" - if err != nil { + cwd, err := os.Getwd() + require.NoError(t, err) + scriptPath := filepath.Join(cwd, "testdata", "compute.jl") + scriptDir := filepath.Dir(scriptPath) + expected := "42\n" + scriptPath + "\n" + scriptDir + + run := func(arg string) string { + t.Helper() + cmd := exec.Command(os.Args[0], "--socket", socketPath, arg) + cmd.Env = append(os.Environ(), "TEST_CLI=1") + cmd.Dir = cwd + out, err := cmd.Output() + stderr := "" if e, ok := err.(*exec.ExitError); ok { stderr = string(e.Stderr) } + require.NoErrorf(t, err, "stderr:\n%s", stderr) + return string(out) } - require.NoErrorf(t, err, "script stderr:\n%s", stderr) - require.Equal(t, "42\n", string(out)) + + require.Equal(t, expected, run(scriptPath), "absolute path") + require.Equal(t, expected, run("testdata/compute.jl"), "relative path resolved against client cwd") } func TestPrintResult(t *testing.T) { diff --git a/go/main.go b/go/main.go index c85f774..1f2107b 100644 --- a/go/main.go +++ b/go/main.go @@ -268,9 +268,9 @@ func main() { } default: - b, err := os.ReadFile(args[0]) - if err == nil { - cmdEval(*socketFlag, string(b), *projectFlag, *sessionFlag, *timeoutFlag, *juliaCmdFlag, false, *freshFlag, *traceFlag) + if _, err := os.Stat(args[0]); err == nil { + code := fmt.Sprintf("cd(%q) do; Base.include(Main, %q); end", mustGetwd(), args[0]) + cmdEval(*socketFlag, code, *projectFlag, *sessionFlag, *timeoutFlag, *juliaCmdFlag, false, *freshFlag, *traceFlag) return } fmt.Fprintf(os.Stderr, "unknown command: %s\n", args[0]) diff --git a/go/testdata/compute.jl b/go/testdata/compute.jl index 47d84c7..ae7baab 100644 --- a/go/testdata/compute.jl +++ b/go/testdata/compute.jl @@ -1 +1 @@ -println(6 * 7) +print(6 * 7, "\n", @__FILE__, "\n", @__DIR__) diff --git a/skills/julia-client/SKILL.md b/skills/julia-client/SKILL.md index e938a79..ca968de 100644 --- a/skills/julia-client/SKILL.md +++ b/skills/julia-client/SKILL.md @@ -5,10 +5,13 @@ description: "Evaluate Julia in long-lived background sessions so imports, varia ## Preferred workflow -Treat `julia-client` like persistent REPL: run setup once with `julia-client -E 'using MyPackage; x = load_fixture()'`, then `julia-client -E 'MyPackage.transform(x)'` to display results while reusing session. After editing package code, `Revise` automatically updates definitions. Do not repeat imports, fixture setup, or `--project=.` for the current directory. +Treat `julia-client` like persistent REPL: run setup once with `julia-client -E 'using MyPackage; x = load_fixture()'`, then `julia-client -E 'MyPackage.transform(x)'` to display results while reusing session. After editing package code, `Revise` automatically updates definitions. -- Don't repeat yourself: avoid repeating same setup in every command. -- Use `--fresh` flag for struct revision (Revise disables by default) or when clean state is required. +- Don't repeat yourself +- Import packages once per session; later calls should use already-loaded names. +- Avoid repeating fixture/setup code in every command. +- Session routing: `--session LABEL` > `--project PROJECT`; default to `--project=@.` when omit both. +- Avoid `--fresh` unless changing struct/type definitions or requiring clean state. ## Other Examples