New provider package @magpie-community/opencode-warp-auth 0.1.0: Warp (the
terminal) AI request credits through the Warp app's sign-in (macOS
Keychain, Windows DPAPI, Linux Secret Service, read-only) or a refresh
token; the account's model list, usage/bonus credits, streaming and tool
calls over Warp's HTTP/2 protobuf API with backpressure. Ships the 1.x
entry (opencode.mjs, main) and the shared 2.x adapter (opencode2.mjs,
exports["."]). Registry entry added. Released through the dist branch
until an owner does the first npm publish.
Reviewed head 62db17e93, merged onto main 6de02a0a. Run there (mote,
temporary HOME): bun test packages/warp 122 pass 0 fail; bun
scripts/check.mjs warp ok; whole repo bun test --timeout 60000 6371 pass
20 skip 0 fail; 2.x load via exports["."] with a fake context registers
both sign-in methods, the warp provider (11 models) and its sdk hook.
Broken by hand: exports -> index.mjs, _internal exported from main,
opencode2.mjs out of files, a one-byte drift in opencode2.mjs, and main
exporting no plugin each make check.mjs fail (the last also the entry
test). Earlier rounds (10-09/10-12, at 0ae2bc3, identical warp code)
broke backpressure, the refresh-token method and the Keychain hex decode
by hand and saw their tests fail.
Not tried: a real Warp account through OpenCode 2.x; Linux with a real
account.
Co-authored-by: guoqchen1001 <guoqchen1001@users.noreply.github.com>
41 lines
1.9 KiB
JavaScript
41 lines
1.9 KiB
JavaScript
import { expect, test } from "bun:test"
|
|
import { _internal as p } from "./index.mjs"
|
|
|
|
test("Value oneofs retain false, empty strings and null presence", () => {
|
|
expect([...p.valueMsg(null).out()]).toEqual([8, 0])
|
|
expect([...p.valueMsg(false).out()]).toEqual([32, 0])
|
|
expect([...p.valueMsg("").out()]).toEqual([26, 0])
|
|
const object = { default: false, enum: ["", null, true], nested: { number: 1.25, negative: -3.5 } }
|
|
expect(p.structOf(p.structPB(object).out())).toEqual(object)
|
|
})
|
|
|
|
test("doubles use protobuf's little endian wire representation", () => {
|
|
expect([...p.valueMsg(1.25).out()]).toEqual([17, 0, 0, 0, 0, 0, 0, 244, 63])
|
|
})
|
|
|
|
test("unsigned varints work beyond uint32 and decode the full uint64 range", () => {
|
|
for (const n of [2 ** 32, 2 ** 40, Number.MAX_SAFE_INTEGER]) expect(p.fields(new p.PB().v(1, n).out())[0].v).toBe(n)
|
|
expect(p.fields(Uint8Array.from([8, ...Array(9).fill(255), 1]))[0].v).toBe(2n ** 64n - 1n)
|
|
expect(() => new p.PB().uv(-1)).toThrow()
|
|
expect(() => new p.PB().uv(Infinity)).toThrow()
|
|
})
|
|
|
|
for (const [name, bytes] of [
|
|
["unterminated varint", [8, 128]], ["oversized uint64", [8, ...Array(10).fill(255)]],
|
|
["truncated bytes", [10, 100, 65]], ["truncated double", [17, 0]],
|
|
["truncated float", [13, 0]], ["zero field number", [0]], ["invalid wire type", [15]],
|
|
]) test(`rejects ${name}`, () => expect(() => p.fields(Uint8Array.from(bytes))).toThrow())
|
|
|
|
test("ordinary strings remain strings, including proto-looking content", () => {
|
|
const object = { text: "\u000fprotobuf wire type 7 [assistant]" }
|
|
expect(p.structOf(p.structPB(object).out())).toEqual(object)
|
|
})
|
|
|
|
test("a __proto__ map key remains data rather than changing the object prototype", () => {
|
|
const object = JSON.parse('{"__proto__":{"polluted":true}}')
|
|
const out = p.structOf(p.structPB(object).out())
|
|
expect(Object.hasOwn(out, "__proto__")).toBe(true)
|
|
expect(Object.getPrototypeOf(out)).toBe(Object.prototype)
|
|
expect(out.polluted).toBeUndefined()
|
|
})
|