Commit Graph
1 Commits
Author SHA1 Message Date
yetone 0d39515b14 gui: Connect's Shell and curl snippets can be for Windows or macOS · Linux, whichever machine runs them (#1514)
FourLeafTec on #1514: at home on Windows, but mostly running things on a
Linux server over ssh, and Connect only ever wrote the snippets for the
machine magpie runs on (PowerShell + curl.exe on Windows, bash elsewhere).

What changes
- Beside the snippet language, the Shell and curl tabs get a two-way
  segmented control, Windows | macOS · Linux. It starts as the host's OS
  (also when Local network / Public address is picked: those say where the
  gateway is reached, not where the snippet is pasted), and the pick is
  kept in localStorage (magpie.snipOS), next to magpie.lang. The Shell tab
  is named PowerShell or Shell after it. Python and Node show no switch.
- Quoting is now right for any key a user brings (ownSecret allows every
  ASCII symbol): POSIX values and headers go in '...' with ' as '\'' when
  they hold ' " $ ` \ !, the -d body escapes its own ', and a URL with
  brackets (a [1m] model id) is quoted and gets -g. PowerShell values go in
  '...' with ' doubled when they hold $ ` "; a header holding " goes to
  curl.exe after --% on one line, quoted as the C runtime reads it, since
  Windows PowerShell 5.1 split such a header in two (seen on the box). A
  %NAME% of a defined variable in such a key is still expanded there; noted
  in the code.
- Translations for the control's label in zh, zh-TW, ja, de.

What was run
- New internal/gui/tests/connect-snippet-shell.test.cjs: Chromium and
  WebKit x en/zh/zh-TW/ja/de x 1100/390 px, 20/20 pass. It picks a LAN
  address on a Win32 page, checks the PowerShell form, switches to
  macOS · Linux (the control's position and the page's scroll unchanged),
  runs the export snippet in bash and zsh and the curl snippet against an
  echo server in the test (the key with ' " $ ! ` \ arrives whole, body
  parses), reloads (pick kept), switches back (--% form), Python shows no
  switch, a Mac page starts on macOS · Linux, and no horizontal overflow.
  With the old app.js it fails: "Expected values to be strictly equal"
  on the PowerShell env snippet ($env:OPENAI_API_KEY="k'ey"$HOME..." was
  unquoted), and there is no .snip-os control at all.
- On the Windows box (Windows PowerShell 5.1.26100; no pwsh there or on
  the Mac): the snippets the GUI made for OpenAI, Anthropic and Gemini,
  each as $env: and curl.exe, with three keys (sk-magpie-key-abc123,
  k'ey"$HOME!`x\y, ab\"cd%PATH%\), run with powershell -File against a
  TcpListener echo server started and stopped by the script. Plain and
  symbol keys arrive whole in the header and $env:, with the body as POST;
  the third shows the %PATH% limit above. Before the --% form, the symbol
  key's header was cut at the " and the request went out as a GET.
- Related GUI tests in both engines (click-scroll, connect-address-kept,
  gateway-*, phone-*, public-url*, omp-profile-connect, i18n-keys): all
  pass except mobile-web's "desktop matches origin/main" for the gateway
  view (415 px), the new control itself; screenshots looked at.
- go test ./internal/gui/ in a sandbox HOME: ok.
2026-10-13 04:57:00 +08:00