diff options
| author | Dax Raad <[email protected]> | 2026-04-25 13:29:52 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2026-04-25 13:30:37 -0400 |
| commit | 1a734adb4d1ce6071432bd68ac45fa4457f0dc2e (patch) | |
| tree | aed9acae5ae3da2fb93d3184ea2dc1f6a9412104 /packages/core/test/effect | |
| parent | a9740b9133a8056f5992b17f1b3fde15cc039f8d (diff) | |
| download | opencode-1a734adb4d1ce6071432bd68ac45fa4457f0dc2e.tar.gz opencode-1a734adb4d1ce6071432bd68ac45fa4457f0dc2e.zip | |
core: consolidate shared infrastructure into core package
Moves effect logging, observability, runtime utilities, flags, installation
version info, and process utilities from opencode to core package. This
enables better code sharing across packages and establishes core as the
single source of truth for foundational utilities.
All internal imports updated to use @opencode-ai/core paths for consistency.
Diffstat (limited to 'packages/core/test/effect')
| -rw-r--r-- | packages/core/test/effect/observability.test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/core/test/effect/observability.test.ts b/packages/core/test/effect/observability.test.ts new file mode 100644 index 000000000..50ea23f89 --- /dev/null +++ b/packages/core/test/effect/observability.test.ts @@ -0,0 +1,46 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { resource } from "@opencode-ai/core/effect/observability" + +const otelResourceAttributes = process.env.OTEL_RESOURCE_ATTRIBUTES +const opencodeClient = process.env.OPENCODE_CLIENT + +afterEach(() => { + if (otelResourceAttributes === undefined) delete process.env.OTEL_RESOURCE_ATTRIBUTES + else process.env.OTEL_RESOURCE_ATTRIBUTES = otelResourceAttributes + + if (opencodeClient === undefined) delete process.env.OPENCODE_CLIENT + else process.env.OPENCODE_CLIENT = opencodeClient +}) + +describe("resource", () => { + test("parses and decodes OTEL resource attributes", () => { + process.env.OTEL_RESOURCE_ATTRIBUTES = + "service.namespace=anomalyco,team=platform%2Cobservability,label=hello%3Dworld,key%2Fname=value%20here" + + expect(resource().attributes).toMatchObject({ + "service.namespace": "anomalyco", + team: "platform,observability", + label: "hello=world", + "key/name": "value here", + }) + }) + + test("drops OTEL resource attributes when any entry is invalid", () => { + process.env.OTEL_RESOURCE_ATTRIBUTES = "service.namespace=anomalyco,broken" + + expect(resource().attributes["service.namespace"]).toBeUndefined() + expect(resource().attributes["opencode.client"]).toBeDefined() + }) + + test("keeps built-in attributes when env values conflict", () => { + process.env.OPENCODE_CLIENT = "cli" + process.env.OTEL_RESOURCE_ATTRIBUTES = + "opencode.client=web,service.instance.id=override,service.namespace=anomalyco" + + expect(resource().attributes).toMatchObject({ + "opencode.client": "cli", + "service.namespace": "anomalyco", + }) + expect(resource().attributes["service.instance.id"]).not.toBe("override") + }) +}) |
