11import * as NodeServices from "@effect/platform-node/NodeServices" ;
2+ import { describe , expect , it } from "@effect/vitest" ;
23import * as Effect from "effect/Effect" ;
34import * as FileSystem from "effect/FileSystem" ;
45import * as Path from "effect/Path" ;
56import * as Schema from "effect/Schema" ;
6- import { describe , expect , it } from "vite-plus/test" ;
7- import { ChildProcessSpawner } from "effect/unstable/process" ;
87import { GrokSettings } from "@t3tools/contracts" ;
98
109import { buildInitialGrokProviderSnapshot , checkGrokProviderStatus } from "./GrokProvider.ts" ;
1110
1211const decodeGrokSettings = Schema . decodeSync ( GrokSettings ) ;
1312
14- const runNode = < A , E > (
15- effect : Effect . Effect <
16- A ,
17- E ,
18- FileSystem . FileSystem | Path . Path | ChildProcessSpawner . ChildProcessSpawner
19- > ,
20- ) : Promise < A > => Effect . runPromise ( effect . pipe ( Effect . provide ( NodeServices . layer ) ) ) ;
21-
2213describe ( "buildInitialGrokProviderSnapshot" , ( ) => {
23- it ( "returns a disabled snapshot when settings.enabled is false" , async ( ) => {
24- const snapshot = await Effect . runPromise (
25- buildInitialGrokProviderSnapshot ( decodeGrokSettings ( { enabled : false } ) ) ,
26- ) ;
27- expect ( snapshot . enabled ) . toBe ( false ) ;
28- expect ( snapshot . status ) . toBe ( "disabled" ) ;
29- expect ( snapshot . installed ) . toBe ( false ) ;
30- expect ( snapshot . message ) . toContain ( "disabled" ) ;
31- } ) ;
14+ it . effect ( "returns a disabled snapshot when settings.enabled is false" , ( ) =>
15+ Effect . gen ( function * ( ) {
16+ const snapshot = yield * buildInitialGrokProviderSnapshot (
17+ decodeGrokSettings ( { enabled : false } ) ,
18+ ) ;
19+ expect ( snapshot . enabled ) . toBe ( false ) ;
20+ expect ( snapshot . status ) . toBe ( "disabled" ) ;
21+ expect ( snapshot . installed ) . toBe ( false ) ;
22+ expect ( snapshot . message ) . toContain ( "disabled" ) ;
23+ } ) ,
24+ ) ;
3225
33- it ( "returns a pending snapshot by default" , async ( ) => {
34- const snapshot = await Effect . runPromise (
35- buildInitialGrokProviderSnapshot ( decodeGrokSettings ( { } ) ) ,
36- ) ;
37- expect ( snapshot . enabled ) . toBe ( true ) ;
38- expect ( snapshot . installed ) . toBe ( true ) ;
39- expect ( snapshot . status ) . toBe ( "warning" ) ;
40- expect ( snapshot . version ) . toBeNull ( ) ;
41- expect ( snapshot . message ) . toContain ( "Checking Grok" ) ;
42- expect ( snapshot . requiresNewThreadForModelChange ) . toBe ( true ) ;
43- } ) ;
26+ it . effect ( "returns a pending snapshot by default" , ( ) =>
27+ Effect . gen ( function * ( ) {
28+ const snapshot = yield * buildInitialGrokProviderSnapshot ( decodeGrokSettings ( { } ) ) ;
29+ expect ( snapshot . enabled ) . toBe ( true ) ;
30+ expect ( snapshot . installed ) . toBe ( true ) ;
31+ expect ( snapshot . status ) . toBe ( "warning" ) ;
32+ expect ( snapshot . version ) . toBeNull ( ) ;
33+ expect ( snapshot . message ) . toContain ( "Checking Grok" ) ;
34+ expect ( snapshot . requiresNewThreadForModelChange ) . toBe ( true ) ;
35+ } ) ,
36+ ) ;
4437} ) ;
4538
46- describe ( "checkGrokProviderStatus" , ( ) => {
47- it ( "reports the binary as missing when the binary path does not resolve" , async ( ) => {
48- const snapshot = await runNode (
49- checkGrokProviderStatus (
39+ it . layer ( NodeServices . layer ) ( "checkGrokProviderStatus" , ( it ) => {
40+ it . effect ( "reports the binary as missing when the binary path does not resolve" , ( ) =>
41+ Effect . gen ( function * ( ) {
42+ const snapshot = yield * checkGrokProviderStatus (
5043 decodeGrokSettings ( {
5144 enabled : true ,
5245 binaryPath : "/definitely/not/installed/grok-binary" ,
5346 } ) ,
54- ) ,
55- ) ;
56- expect ( snapshot . enabled ) . toBe ( true ) ;
57- expect ( snapshot . installed ) . toBe ( false ) ;
58- expect ( snapshot . status ) . toBe ( "error" ) ;
59- expect ( snapshot . message ) . toMatch ( / n o t i n s t a l l e d | n o t o n P A T H | F a i l e d t o e x e c u t e / ) ;
60- } ) ;
47+ ) ;
48+ expect ( snapshot . enabled ) . toBe ( true ) ;
49+ expect ( snapshot . installed ) . toBe ( false ) ;
50+ expect ( snapshot . status ) . toBe ( "error" ) ;
51+ expect ( snapshot . message ) . toMatch ( / n o t i n s t a l l e d | n o t o n P A T H | F a i l e d t o e x e c u t e / ) ;
52+ } ) ,
53+ ) ;
6154
62- it ( "reports an installed CLI as unhealthy when --version exits non-zero" , async ( ) => {
63- const snapshot = await runNode (
64- Effect . scoped (
55+ it . effect ( "reports an installed CLI as unhealthy when --version exits non-zero" , ( ) =>
56+ Effect . gen ( function * ( ) {
57+ const snapshot = yield * Effect . scoped (
6558 Effect . gen ( function * ( ) {
6659 const fs = yield * FileSystem . FileSystem ;
6760 const path = yield * Path . Path ;
@@ -77,18 +70,18 @@ describe("checkGrokProviderStatus", () => {
7770 decodeGrokSettings ( { enabled : true , binaryPath : grokPath } ) ,
7871 ) ;
7972 } ) ,
80- ) ,
81- ) ;
73+ ) ;
8274
83- expect ( snapshot . enabled ) . toBe ( true ) ;
84- expect ( snapshot . installed ) . toBe ( true ) ;
85- expect ( snapshot . status ) . toBe ( "error" ) ;
86- expect ( snapshot . message ) . toContain ( "broken grok install" ) ;
87- } ) ;
75+ expect ( snapshot . enabled ) . toBe ( true ) ;
76+ expect ( snapshot . installed ) . toBe ( true ) ;
77+ expect ( snapshot . status ) . toBe ( "error" ) ;
78+ expect ( snapshot . message ) . toContain ( "broken grok install" ) ;
79+ } ) ,
80+ ) ;
8881
89- it ( "reports an error when ACP model discovery is unavailable" , async ( ) => {
90- const snapshot = await runNode (
91- Effect . scoped (
82+ it . effect ( "reports an error when ACP model discovery is unavailable" , ( ) =>
83+ Effect . gen ( function * ( ) {
84+ const snapshot = yield * Effect . scoped (
9285 Effect . gen ( function * ( ) {
9386 const fs = yield * FileSystem . FileSystem ;
9487 const path = yield * Path . Path ;
@@ -104,12 +97,12 @@ describe("checkGrokProviderStatus", () => {
10497 decodeGrokSettings ( { enabled : true , binaryPath : grokPath } ) ,
10598 ) ;
10699 } ) ,
107- ) ,
108- ) ;
100+ ) ;
109101
110- expect ( snapshot . status ) . toBe ( "error" ) ;
111- expect ( snapshot . installed ) . toBe ( true ) ;
112- expect ( snapshot . models . map ( ( model ) => model . slug ) ) . toEqual ( [ "grok-build" ] ) ;
113- expect ( snapshot . message ) . toContain ( "ACP startup failed" ) ;
114- } ) ;
102+ expect ( snapshot . status ) . toBe ( "error" ) ;
103+ expect ( snapshot . installed ) . toBe ( true ) ;
104+ expect ( snapshot . models . map ( ( model ) => model . slug ) ) . toEqual ( [ "grok-build" ] ) ;
105+ expect ( snapshot . message ) . toContain ( "ACP startup failed" ) ;
106+ } ) ,
107+ ) ;
115108} ) ;
0 commit comments