11/**
22 * MCP server integration tests.
33 *
4- * Tests the thin MCP layer (state holder) on top of Rolex .
5- * Business logic (RoleContext ) is tested in rolexjs /tests/context .test.ts.
4+ * Tests the thin MCP layer (state holder) on top of RoleX .
5+ * Business logic (Role model ) is tested in core /tests/unit/role-model .test.ts.
66 * Render is now in rolexjs — Role methods return rendered strings directly.
77 */
88import { beforeEach , describe , expect , it } from "bun:test" ;
9+ import type { CommandResult } from "@rolexjs/core" ;
910import { localPlatform } from "@rolexjs/local-platform" ;
10- import type { CommandResult } from "@ rolexjs/prototype " ;
11- import { createRoleX , type Rolex , render } from "rolexjs" ;
11+ import { createRoleX , type RoleX } from "rolexjs" ;
12+ import { render } from "../../../packages/ rolexjs/src/render.js " ;
1213import { McpState } from "../src/state.js" ;
1314
14- let rolex : Rolex ;
15+ let rolex : RoleX ;
1516let state : McpState ;
1617
1718beforeEach ( async ( ) => {
@@ -33,7 +34,7 @@ describe("requireRole", () => {
3334 const role = await rolex . activate ( "sean" ) ;
3435 state . role = role ;
3536 expect ( state . requireRole ( ) ) . toBe ( role ) ;
36- expect ( state . requireRole ( ) . roleId ) . toBe ( "sean" ) ;
37+ expect ( state . requireRole ( ) . id ) . toBe ( "sean" ) ;
3738 } ) ;
3839} ) ;
3940
@@ -104,19 +105,18 @@ describe("render", () => {
104105
105106describe ( "full execution flow" , ( ) => {
106107 it ( "completes want → plan → todo → finish → reflect → realize through Role API" , async ( ) => {
107- // Born + activate
108108 await rolex . direct ( "!individual.born" , { content : "Feature: Sean" , id : "sean" } ) ;
109109 const role = await rolex . activate ( "sean" ) ;
110110 state . role = role ;
111111
112112 // Want
113113 const goal = await role . want ( "Feature: Build Auth" , "build-auth" ) ;
114- expect ( role . ctx . focusedGoalId ) . toBe ( "build-auth" ) ;
114+ expect ( role . snapshot ( ) . focusedGoalId ) . toBe ( "build-auth" ) ;
115115 expect ( goal ) . toContain ( "I →" ) ;
116116
117117 // Plan
118118 const plan = await role . plan ( "Feature: Auth Plan" , "auth-plan" ) ;
119- expect ( role . ctx . focusedPlanId ) . toBe ( "auth-plan" ) ;
119+ expect ( role . snapshot ( ) . focusedPlanId ) . toBe ( "auth-plan" ) ;
120120 expect ( plan ) . toContain ( "I →" ) ;
121121
122122 // Todo
@@ -129,7 +129,7 @@ describe("full execution flow", () => {
129129 "Feature: Implemented JWT\n Scenario: Token pattern\n Given JWT needed\n Then tokens work"
130130 ) ;
131131 expect ( finished ) . toContain ( "[encounter]" ) ;
132- expect ( role . ctx . encounterIds . has ( "impl-jwt-finished" ) ) . toBe ( true ) ;
132+ expect ( role . snapshot ( ) . encounterIds ) . toContain ( "impl-jwt-finished" ) ;
133133
134134 // Reflect: encounter → experience
135135 const reflected = await role . reflect (
@@ -138,8 +138,8 @@ describe("full execution flow", () => {
138138 "token-insight"
139139 ) ;
140140 expect ( reflected ) . toContain ( "[experience]" ) ;
141- expect ( role . ctx . encounterIds . has ( "impl-jwt-finished" ) ) . toBe ( false ) ;
142- expect ( role . ctx . experienceIds . has ( "token-insight" ) ) . toBe ( true ) ;
141+ expect ( role . snapshot ( ) . encounterIds ) . not . toContain ( "impl-jwt-finished" ) ;
142+ expect ( role . snapshot ( ) . experienceIds ) . toContain ( "token-insight" ) ;
143143
144144 // Realize: experience → principle
145145 const realized = await role . realize (
@@ -148,7 +148,7 @@ describe("full execution flow", () => {
148148 "refresh-tokens"
149149 ) ;
150150 expect ( realized ) . toContain ( "[principle]" ) ;
151- expect ( role . ctx . experienceIds . has ( "token-insight" ) ) . toBe ( false ) ;
151+ expect ( role . snapshot ( ) . experienceIds ) . not . toContain ( "token-insight" ) ;
152152 } ) ;
153153} ) ;
154154
@@ -163,14 +163,14 @@ describe("focus", () => {
163163 state . role = role ;
164164
165165 await role . want ( "Feature: Goal A" , "goal-a" ) ;
166- expect ( role . ctx . focusedGoalId ) . toBe ( "goal-a" ) ;
166+ expect ( role . snapshot ( ) . focusedGoalId ) . toBe ( "goal-a" ) ;
167167
168168 await role . want ( "Feature: Goal B" , "goal-b" ) ;
169- expect ( role . ctx . focusedGoalId ) . toBe ( "goal-b" ) ;
169+ expect ( role . snapshot ( ) . focusedGoalId ) . toBe ( "goal-b" ) ;
170170
171171 // Switch back to goal A
172172 await role . focus ( "goal-a" ) ;
173- expect ( role . ctx . focusedGoalId ) . toBe ( "goal-a" ) ;
173+ expect ( role . snapshot ( ) . focusedGoalId ) . toBe ( "goal-a" ) ;
174174 } ) ;
175175} ) ;
176176
@@ -179,18 +179,16 @@ describe("focus", () => {
179179// ================================================================
180180
181181describe ( "selective cognition" , ( ) => {
182- it ( "ctx tracks multiple encounters, reflect consumes selectively" , async ( ) => {
182+ it ( "tracks multiple encounters, reflect consumes selectively" , async ( ) => {
183183 await rolex . direct ( "!individual.born" , { content : "Feature: Sean" , id : "sean" } ) ;
184184 const role = await rolex . activate ( "sean" ) ;
185185 state . role = role ;
186186
187- // Create goal + plan + tasks
188187 await role . want ( "Feature: Auth" , "auth" ) ;
189188 await role . plan ( "Feature: Plan" , "plan1" ) ;
190189 await role . todo ( "Feature: Login" , "login" ) ;
191190 await role . todo ( "Feature: Signup" , "signup" ) ;
192191
193- // Finish both with encounters
194192 await role . finish (
195193 "login" ,
196194 "Feature: Login done\n Scenario: OK\n Given login\n Then success"
@@ -200,8 +198,8 @@ describe("selective cognition", () => {
200198 "Feature: Signup done\n Scenario: OK\n Given signup\n Then success"
201199 ) ;
202200
203- expect ( role . ctx . encounterIds . has ( "login-finished" ) ) . toBe ( true ) ;
204- expect ( role . ctx . encounterIds . has ( "signup-finished" ) ) . toBe ( true ) ;
201+ expect ( role . snapshot ( ) . encounterIds ) . toContain ( "login-finished" ) ;
202+ expect ( role . snapshot ( ) . encounterIds ) . toContain ( "signup-finished" ) ;
205203
206204 // Reflect only on "login-finished"
207205 await role . reflect (
@@ -211,9 +209,9 @@ describe("selective cognition", () => {
211209 ) ;
212210
213211 // "login-finished" consumed, "signup-finished" still available
214- expect ( role . ctx . encounterIds . has ( "login-finished" ) ) . toBe ( false ) ;
215- expect ( role . ctx . encounterIds . has ( "signup -finished") ) . toBe ( true ) ;
216- // Experience registered
217- expect ( role . ctx . experienceIds . has ( "login-insight" ) ) . toBe ( true ) ;
212+ const snap = role . snapshot ( ) ;
213+ expect ( snap . encounterIds ) . not . toContain ( "login -finished") ;
214+ expect ( snap . encounterIds ) . toContain ( "signup-finished" ) ;
215+ expect ( snap . experienceIds ) . toContain ( "login-insight" ) ;
218216 } ) ;
219217} ) ;
0 commit comments