|
|
@@ -161,7 +161,7 @@ describe("Config", () => {
|
|
|
),
|
|
|
)
|
|
|
|
|
|
- it.live("loads JSON and JSONC files from lowest to highest priority", () =>
|
|
|
+ it.live("loads opencode JSON and JSONC files from lowest to highest priority", () =>
|
|
|
Effect.acquireRelease(
|
|
|
Effect.promise(() => tmpdir()),
|
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
|
@@ -170,13 +170,9 @@ describe("Config", () => {
|
|
|
Effect.gen(function* () {
|
|
|
yield* Effect.promise(() =>
|
|
|
Promise.all([
|
|
|
- fs.writeFile(
|
|
|
- path.join(tmp.path, "config.json"),
|
|
|
- JSON.stringify({ $schema: "base", providers: { base: provider } }),
|
|
|
- ),
|
|
|
fs.writeFile(
|
|
|
path.join(tmp.path, "opencode.json"),
|
|
|
- JSON.stringify({ $schema: "middle", providers: { middle: provider } }),
|
|
|
+ JSON.stringify({ $schema: "base", providers: { base: provider } }),
|
|
|
),
|
|
|
fs.writeFile(
|
|
|
path.join(tmp.path, "opencode.jsonc"),
|
|
|
@@ -192,12 +188,12 @@ describe("Config", () => {
|
|
|
const config = yield* Config.Service
|
|
|
const documents = (yield* config.entries()).filter((entry) => entry.type === "document")
|
|
|
|
|
|
- expect(documents).toHaveLength(3)
|
|
|
- expect(documents.map((document) => document.type)).toEqual(["document", "document", "document"])
|
|
|
- expect(documents.map((document) => document.info.$schema)).toEqual(["base", "middle", "last"])
|
|
|
+ expect(documents).toHaveLength(2)
|
|
|
+ expect(documents.map((document) => document.type)).toEqual(["document", "document"])
|
|
|
+ expect(documents.map((document) => document.info.$schema)).toEqual(["base", "last"])
|
|
|
expect(documents[0]).toBeInstanceOf(Config.Document)
|
|
|
- expect(documents[0]?.path).toBe(path.join(tmp.path, "config.json"))
|
|
|
- expect(documents[2]?.info.providers?.last).toBeInstanceOf(ConfigProvider.Info)
|
|
|
+ expect(documents[0]?.path).toBe(path.join(tmp.path, "opencode.json"))
|
|
|
+ expect(documents[1]?.info.providers?.last).toBeInstanceOf(ConfigProvider.Info)
|
|
|
|
|
|
yield* Effect.promise(() =>
|
|
|
fs.writeFile(path.join(tmp.path, "opencode.jsonc"), JSON.stringify({ $schema: "changed" })),
|
|
|
@@ -206,7 +202,29 @@ describe("Config", () => {
|
|
|
(yield* config.entries())
|
|
|
.filter((entry) => entry.type === "document")
|
|
|
.map((document) => document.info.$schema),
|
|
|
- ).toEqual(["base", "middle", "last"])
|
|
|
+ ).toEqual(["base", "last"])
|
|
|
+ }).pipe(Effect.provide(testLayer(tmp.path)))
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ it.live("does not load legacy config.json files", () =>
|
|
|
+ Effect.acquireRelease(
|
|
|
+ Effect.promise(() => tmpdir()),
|
|
|
+ (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
|
+ ).pipe(
|
|
|
+ Effect.flatMap((tmp) =>
|
|
|
+ Effect.gen(function* () {
|
|
|
+ yield* Effect.promise(() =>
|
|
|
+ fs.writeFile(path.join(tmp.path, "config.json"), JSON.stringify({ $schema: "legacy" })),
|
|
|
+ )
|
|
|
+
|
|
|
+ return yield* Effect.gen(function* () {
|
|
|
+ const config = yield* Config.Service
|
|
|
+ const documents = (yield* config.entries()).filter((entry) => entry.type === "document")
|
|
|
+
|
|
|
+ expect(documents).toHaveLength(0)
|
|
|
}).pipe(Effect.provide(testLayer(tmp.path)))
|
|
|
}),
|
|
|
),
|
|
|
@@ -648,7 +666,7 @@ describe("Config", () => {
|
|
|
),
|
|
|
)
|
|
|
|
|
|
- it.live("ignores invalid files while loading valid config values", () =>
|
|
|
+ it.live("ignores an invalid file while loading valid config values", () =>
|
|
|
Effect.acquireRelease(
|
|
|
Effect.promise(() => tmpdir()),
|
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
|
@@ -657,9 +675,8 @@ describe("Config", () => {
|
|
|
Effect.gen(function* () {
|
|
|
yield* Effect.promise(() =>
|
|
|
Promise.all([
|
|
|
- fs.writeFile(path.join(tmp.path, "config.json"), JSON.stringify({ $schema: "base" })),
|
|
|
- fs.writeFile(path.join(tmp.path, "opencode.json"), "{ invalid"),
|
|
|
- fs.writeFile(path.join(tmp.path, "opencode.jsonc"), JSON.stringify({ providers: { invalid: true } })),
|
|
|
+ fs.writeFile(path.join(tmp.path, "opencode.json"), JSON.stringify({ $schema: "base" })),
|
|
|
+ fs.writeFile(path.join(tmp.path, "opencode.jsonc"), "{ invalid"),
|
|
|
]),
|
|
|
)
|
|
|
return yield* Effect.gen(function* () {
|
|
|
@@ -728,7 +745,7 @@ describe("Config", () => {
|
|
|
fs.writeFile(path.join(global, "opencode.json"), JSON.stringify({ $schema: "global" })),
|
|
|
fs.writeFile(path.join(root, "opencode.json"), JSON.stringify({ $schema: "root" })),
|
|
|
fs.writeFile(path.join(parent, "opencode.jsonc"), JSON.stringify({ $schema: "parent" })),
|
|
|
- fs.writeFile(path.join(directory, "config.json"), JSON.stringify({ $schema: "directory" })),
|
|
|
+ fs.writeFile(path.join(directory, "opencode.json"), JSON.stringify({ $schema: "directory" })),
|
|
|
fs.writeFile(path.join(root, ".opencode", "opencode.json"), JSON.stringify({ $schema: "root-dot" })),
|
|
|
fs.writeFile(
|
|
|
path.join(directory, ".opencode", "opencode.jsonc"),
|