Skip to content

[CLI] Add test that /model mid-session switch does not leak to global chatModel #172

Description

@charlesgreen

Context

Follow-up from multi-agent review of #164/#165/#167/#168 cleanup on branch fix/cli-chat-cleanup.

TestSnapshotChatOptions verifies the global -> snapshot isolation invariant (post-snapshot mutation of chatModel does not leak into the snapshot). The symmetric invariant — that in-session /model switches mutate the local opts.Model and NOT the package-level chatModel — is the load-bearing contract of #164 but is currently unverified by tests.

Why deferred

Testing handleCommand directly requires instantiating a real *coordinator.Coordinator, which performs provider setup. That would need a mock coordinator abstraction, which is a larger refactor than the cleanup PR warranted.

Proposal

Option A: Introduce a small coordinatorSetter interface in cmd/aixgo/cmd that *coordinator.Coordinator satisfies (just SetModel(string) error + ClearHistory()), then have handleCommand accept the interface. A fake can be stubbed for the test.

Option B: Extract the /model branch of handleCommand into a pure helper that takes (opts *chatOptions, sess *session.Session, newModel string, setter func(string) error) and write a direct unit test on the helper.

Either approach is cheap once chosen; flag for bikeshedding.

Acceptance

  • Test fails if someone re-introduces chatModel = newModel in the /model handler
  • Test runs under -race without new globals

Labels

cli, test, follow-up

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions