Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Builds a test subscription service backed by a mutable set of subscribed
* changeset URIs, so service tests can simulate subscribe / unsubscribe
* without wiring up the coordinator.
*/
function
createSubscriptionService
(
...
:
string
[
]
)
:
&
{
readonly
:
<
string
>
}
{
const
=
new
Set
(
)
;
return
{
:
undefined
,
,
:
.
,
getSessionSubscriptions
:
(
)
=>
,
addSubscription
:
(
,
)
=>
{
.
add
(
)
;
}
,
removeSubscription
:
(
,
)
=>
{
.
delete
(
)
;
}
,
clearSessionSubscriptions
:
(
)
=>
{
.
clear
(
)
;
}
,
}
;
}
/**
* Builds a no-op changeset operation service for tests. It advertises no
* operations, which mirrors the default behaviour of a session without any
* operation contributions.
*/
function
createOperationService
(
)
:
{
return
{
:
undefined
,
registerContribution
:
(
)
=>
toDisposable
(
(
)
=>
{
}
)
,
updateOperations
:
(
)
=>
{
}
,
getOperations
:
(
)
=>
undefined
,
invokeChangesetOperation
:
async
(
)
=>
{
throw
new
Error
(
'not implemented'
)
;
}
,
dispose
:
(
)
=>
{
}
,
}
;
}
/** Captures `publicLog2` telemetry events so tests can assert on emitted fields. */
class
CapturingTelemetryService
implements
ITelemetryService
{
declare
readonly
:
undefined
;
readonly
=
.
USAGE
;
readonly
=
'test-session'
;
readonly
=
'test-machine'
;
readonly
=
'test-sqm'
;
readonly
=
'test-dev-device'
;
readonly
=
'test-first-session-date'
;
readonly
=
false
;
readonly
:
{
:
string
;
:
<
string
,
unknown
>
}
[
]
=
[
]
;
publicLog
(
)
:
void
{
}
publicLog2
(
:
string
,
?
:
<
string
,
unknown
>
)
:
void
{
this
.
.
push
(
{
,
:
??
{
}
}
)
;
}
publicLogError
(
)
:
void
{
}
publicLogError2
(
:
string
,
?
:
<
string
,
unknown
>
)
:
void
{
this
.
.
push
(
{
,
:
??
{
}
}
)
;
}
setExperimentProperty
(
)
:
void
{
}
setCommonProperty
(
)
:
void
{
}
}
.
skip
(
'AgentHostChangesetService'
,
(
)
=>
{
const
=
new
DisposableStore
(
)
;
let
:
;
let
:
;
const
=
.
uri
(
'mock'
,
'session-1'
)
;
function
setupSession
(
?
:
string
)
:
void
{
.
createSession
(
{
:
.
toString
(
)
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
{
:
'file:///test-project'
,
:
'Test Project'
}
,
:
?
[
]
:
undefined
,
}
)
;
.
setSessionChangesets
(
.
toString
(
)
,
buildDefaultChangesetCatalog
(
.
toString
(
)
)
)
;
.
dispatchServerAction
(
.
toString
(
)
,
{
:
.
,
}
)
;
}
setup
(
(
)
=>
{
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
createNullSessionDataService
(
)
,
createNoopGitService
(
)
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
buildUncommittedChangesetUri
(
.
toString
(
)
)
)
,
NULL_REVIEW_SERVICE
,
,
)
)
;
}
)
;
teardown
(
(
)
=>
{
.
clear
(
)
;
}
)
;
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'registerStaticChangesets makes the two static changeset URIs subscribable with computing status'
,
(
)
=>
{
const
=
.
toString
(
)
;
setupSession
(
)
;
// Catalogue is seeded by setupSession (mirrors what `_buildInitialSummary`
// does in production) — sanity check before exercising registration.
.
deepStrictEqual
(
.
getSessionState
(
)
?.
,
[
{
:
'Branch Changes'
,
:
`${sessionStr}/changeset/session`
,
:
'session'
}
,
{
:
'Uncommitted Changes'
,
:
`${sessionStr}/changeset/uncommitted`
,
:
'Show uncommitted changes in this session'
,
:
'uncommitted'
}
,
]
)
;
.
registerStaticChangesets
(
)
;
// Both static changeset URIs are now registered and subscribable
// with `computing` snapshots so a client that subscribes before
// the first compute pass sees a valid state.
for
(
const
of
[
'uncommitted'
,
'session'
]
)
{
const
=
.
getSnapshot
(
`${sessionStr}/changeset/${id}`
)
;
.
ok
(
,
`expected ${id} changeset URI to be subscribable`
)
;
.
strictEqual
(
(
.
as
{
:
string
}
)
.
,
'computing'
)
;
}
// Registration must not mutate the seeded catalogue.
.
deepStrictEqual
(
.
getSessionState
(
)
?.
,
[
{
:
'Branch Changes'
,
:
`${sessionStr}/changeset/session`
,
:
'session'
}
,
{
:
'Uncommitted Changes'
,
:
`${sessionStr}/changeset/uncommitted`
,
:
'Show uncommitted changes in this session'
,
:
'uncommitted'
}
,
]
)
;
}
)
;
test
(
'registerStaticChangesets is idempotent across repeated calls'
,
(
)
=>
{
const
=
.
toString
(
)
;
setupSession
(
)
;
.
registerStaticChangesets
(
)
;
.
registerStaticChangesets
(
)
;
.
registerStaticChangesets
(
)
;
const
=
.
getSessionState
(
)
?.
;
.
strictEqual
(
?.
,
5
,
'expected the three default catalogue entries'
)
;
}
)
;
test
(
'restoreStaticChangeset publishes files in Ready and refreshes catalogue counts'
,
(
)
=>
{
const
=
.
toString
(
)
;
setupSession
(
)
;
const
=
[
{
:
{
:
'file:///wd/a.ts'
,
:
{
:
'file:///wd/a.ts'
}
}
,
:
{
:
5
,
:
2
}
,
}
,
{
:
{
:
'file:///wd/b.ts'
,
:
{
:
'file:///wd/b.ts'
}
}
,
:
{
:
1
,
:
0
}
,
}
,
]
;
.
restoreStaticChangeset
(
,
'session'
,
)
;
const
=
`${sessionStr}/changeset/session`
;
const
=
.
getSnapshot
(
)
;
.
ok
(
,
'expected the changeset URI to be subscribable'
)
;
const
=
.
as
{
:
string
;
:
Array
<
{
:
string
}
>
}
;
.
strictEqual
(
.
,
'ready'
)
;
.
deepStrictEqual
(
.
.
map
(
=>
.
)
,
[
'file:///wd/a.ts'
,
'file:///wd/b.ts'
]
)
;
const
=
.
getSessionState
(
)
?.
;
.
deepStrictEqual
(
,
[
{
:
'Branch Changes'
,
:
,
:
'session'
,
}
,
{
:
'Uncommitted Changes'
,
:
`${sessionStr}/changeset/uncommitted`
,
:
'Show uncommitted changes in this session'
,
:
'uncommitted'
,
}
,
]
)
;
}
)
;
test
(
'restoreStaticChangeset catalogue counts only emitted unique files'
,
(
)
=>
{
const
=
.
toString
(
)
;
setupSession
(
)
;
const
=
[
{
:
{
:
'file:///wd/a.ts'
,
:
{
:
'file:///wd/a.ts'
}
}
,
:
{
:
100
,
:
50
}
,
}
,
{
:
{
:
20
,
:
10
}
,
}
,
{
:
{
:
'file:///wd/a.ts'
,
:
{
:
'file:///wd/a.ts'
}
}
,
:
{
:
3
,
:
1
}
,
}
,
{
:
{
:
'file:///wd/b.ts'
,
:
{
:
'file:///wd/b.ts'
}
}
,
:
{
:
1
,
:
0
}
,
}
,
]
;
.
restoreStaticChangeset
(
,
'session'
,
)
;
const
=
`${sessionStr}/changeset/session`
;
const
=
.
getSnapshot
(
)
;
const
=
?.
as
{
:
Array
<
{
:
string
;
:
{
?
:
{
?
:
number
;
?
:
number
}
}
}
>
}
|
undefined
;
const
=
.
getSessionState
(
)
?.
;
.
deepStrictEqual
(
{
:
?.
.
map
(
=>
(
{
:
.
,
:
.
.
}
)
)
,
,
}
,
{
:
[
{
:
'file:///wd/a.ts'
,
:
{
:
3
,
:
1
}
}
,
{
:
'file:///wd/b.ts'
,
:
{
:
1
,
:
0
}
}
,
]
,
:
[
{
:
'Branch Changes'
,
:
,
:
'session'
,
}
,
{
:
'Uncommitted Changes'
,
:
`${sessionStr}/changeset/uncommitted`
,
:
'Show uncommitted changes in this session'
,
:
'uncommitted'
,
}
,
]
,
}
)
;
}
)
;
test
(
'restoreStaticChangeset works without a live session state (seeds the changeset for unopened sessions)'
,
(
)
=>
{
const
=
.
toString
(
)
;
// Note: setupSession is intentionally NOT called.
const
=
[
{
:
{
:
'file:///wd/a.ts'
,
:
{
:
'file:///wd/a.ts'
}
}
,
:
{
:
1
,
:
0
}
,
}
,
]
;
.
restoreStaticChangeset
(
,
'session'
,
)
;
// Session state still doesn't exist — only the changeset
// state is registered so a client subscription resolves.
.
strictEqual
(
.
getSessionState
(
)
,
undefined
)
;
const
=
.
getSnapshot
(
`${sessionStr}/changeset/session`
)
;
.
ok
(
,
'expected the changeset URI to be subscribable even without a session state'
)
;
const
=
.
as
{
:
string
;
:
Array
<
{
:
string
}
>
}
;
.
strictEqual
(
.
,
'ready'
)
;
.
deepStrictEqual
(
.
.
map
(
=>
.
)
,
[
'file:///wd/a.ts'
]
)
;
}
)
;
suite
(
'session diff computation'
,
(
)
=>
{
test
(
'git-driven path is preferred when a git service is provided and the working dir is a git work tree'
,
async
(
)
=>
{
const
=
new
SessionDatabase
(
':memory:'
)
;
.
add
(
toDisposable
(
(
)
=>
.
close
(
)
)
)
;
const
=
createSessionDataService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
[
{
:
{
:
'file:///wd/new.ts'
,
:
{
:
'file:///wd/new.ts'
}
}
,
:
{
:
1
,
:
0
}
,
}
]
;
const
:
{
:
string
;
:
string
;
:
string
|
undefined
}
[
]
=
[
]
;
const
=
{
computeSessionFileDiffs
:
async
(
:
URI
,
:
{
:
string
;
?
:
string
}
)
=>
{
.
push
(
{
:
.
toString
(
)
,
:
.
,
:
.
}
)
;
return
;
}
,
}
as
unknown
as
;
const
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
buildUncommittedChangesetUri
(
.
toString
(
)
)
)
,
NULL_REVIEW_SERVICE
,
)
)
;
.
createSession
(
{
:
.
toString
(
)
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///wd'
]
,
}
)
;
await
.
setMetadata
(
'agentHost.diffBaseBranch'
,
'main'
)
;
const
:
[
]
=
[
]
;
.
add
(
.
onDidEmitEnvelope
(
=>
{
.
push
(
)
;
}
)
)
;
// Trigger a turn-complete (which fires the immediate diff path).
// The uncommitted subscription makes on-turn-complete compute that
// slot alongside the session-wide one.
.
onTurnComplete
(
.
toString
(
)
,
'turn-1'
)
;
// Turn-complete recomputes both the uncommitted and the
// session-wide changesets via the per-key sequencer; wait
// deterministically until both git calls have been observed
// rather than racing on the first dispatched envelope.
for
(
let
=
0
;
<
200
&&
.
length<2; i++){awaittimeout(2);}// Turn-complete recomputes both the uncommitted (no// `baseBranch`) and the session-wide (with `baseBranch`)// changesets in parallel; assert both ran with the right// options regardless of order.const sortedCalls =[...computeCalls].sort((a, b)=>
(
.
??
''
)
<
(
.
??
''
)
?
-
1
:
1
)
;
.
deepStrictEqual
(
,
[
{
:
'file:///wd'
,
:
.
toString
(
)
,
:
undefined
}
,
{
:
'file:///wd'
,
:
.
toString
(
)
,
:
'main'
}
,
]
)
;
// Each compute pass lands as a single `changeset/contentChanged`
// envelope carrying the full file list. Walk the captured stream
// and reconstruct the per-changeset file lists to assert each
// matches the git service output.
const
=
.
filter
(
=>
.
.
===
.
)
as
Array
<
{
:
string
;
:
{
:
Array
<
{
:
unknown
}
>
}
}
>
;
const
=
.
filter
(
=>
.
===
`${sessionUri.toString()}/changeset/session`
)
;
const
=
.
filter
(
=>
.
===
`${sessionUri.toString()}/changeset/uncommitted`
)
;
.
deepStrictEqual
(
.
at
(
-
1
)
?.
.
.
map
(
=>
.
)
,
)
;
.
deepStrictEqual
(
.
at
(
-
1
)
?.
.
.
map
(
=>
.
)
,
)
;
// The compute pass also persists the file list under the
// legacy `'diffs'` slot so it survives restarts. The write
// is fire-and-forget through the metadata sequencer; poll
// briefly until it lands.
let
:
string
|
undefined
;
for
(
let
=
0
;
<
50
&&
!
;
++
)
{
await
timeout
(
2
)
;
=
await
.
getMetadata
(
'diffs'
)
;
}
.
ok
(
,
'expected the compute pass to persist diffs to the session DB'
)
;
.
deepStrictEqual
(
JSON
.
parse
(
)
,
)
;
}
)
;
test
(
'session changeset falls back to _meta.git base branch when persisted diff base is absent'
,
async
(
)
=>
{
const
=
new
SessionDatabase
(
':memory:'
)
;
.
add
(
toDisposable
(
(
)
=>
.
close
(
)
)
)
;
const
=
createSessionDataService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
:
{
:
string
|
undefined
}
[
]
=
[
]
;
const
=
{
computeSessionFileDiffs
:
async
(
:
URI
,
:
{
:
string
;
?
:
string
}
)
=>
{
.
push
(
{
:
.
}
)
;
return
[
]
;
}
,
}
as
unknown
as
;
const
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
buildUncommittedChangesetUri
(
.
toString
(
)
)
)
,
NULL_REVIEW_SERVICE
,
)
)
;
const
=
.
toString
(
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///wd'
]
,
}
)
;
.
setSessionMeta
(
,
withSessionGitState
(
undefined
,
{
:
'main'
}
)
)
;
.
refreshSessionChangeset
(
)
;
for
(
let
=
0
;
<
50
&&
.
===
0
;
++
)
{
await
timeout
(
2
)
;
}
.
deepStrictEqual
(
,
[
{
:
'main'
}
]
)
;
}
)
;
test
(
'session changeset keeps persisted diff base ahead of _meta.git base branch'
,
async
(
)
=>
{
const
=
new
SessionDatabase
(
':memory:'
)
;
.
add
(
toDisposable
(
(
)
=>
.
close
(
)
)
)
;
await
.
setMetadata
(
'agentHost.diffBaseBranch'
,
'release'
)
;
const
=
createSessionDataService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
:
{
:
string
|
undefined
}
[
]
=
[
]
;
const
=
{
computeSessionFileDiffs
:
async
(
:
URI
,
:
{
:
string
;
?
:
string
}
)
=>
{
.
push
(
{
:
.
}
)
;
return
[
]
;
}
,
}
as
unknown
as
;
const
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
)
,
NULL_REVIEW_SERVICE
,
)
)
;
const
=
.
toString
(
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///wd'
]
,
}
)
;
.
setSessionMeta
(
,
withSessionGitState
(
undefined
,
{
:
'main'
}
)
)
;
.
refreshSessionChangeset
(
)
;
for
(
let
=
0
;
<
50
&&
.
===
0
;
++
)
{
await
timeout
(
2
)
;
}
.
deepStrictEqual
(
,
[
{
:
'release'
}
]
)
;
}
)
;
test
(
'falls back to the edit-tracker aggregator when the git service returns undefined'
,
async
(
)
=>
{
const
=
new
SessionDatabase
(
':memory:'
)
;
.
add
(
toDisposable
(
(
)
=>
.
close
(
)
)
)
;
const
=
createSessionDataService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
{
computeSessionFileDiffs
:
async
(
)
=>
undefined
,
}
as
unknown
as
;
const
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
)
,
NULL_REVIEW_SERVICE
,
)
)
;
.
createSession
(
{
:
.
toString
(
)
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///wd'
]
,
}
)
;
const
:
[
]
=
[
]
;
let
:
(
(
)
=>
void
)
|
undefined
;
const
=
new
Promise<void>
(
=>
{
=
;
}
)
;
.
add
(
.
onDidEmitEnvelope
(
=>
{
.
push
(
)
;
if
(
.
.
===
.
)
{
?.
(
)
;
}
}
)
)
;
.
onTurnComplete
(
.
toString
(
)
,
'turn-1'
)
;
await
;
// With no recorded edits, the edit-tracker aggregator returns an
// empty array — the single `changeset/contentChanged` envelope
// carries an empty file list. The important assertion is that we
// still ran the producer through to a `changeset/statusChanged →
// ready` envelope, which proves the fallback path executed without
// throwing.
const
=
.
map
(
=>
.
)
.
filter
(
=>
.
===
.
)
as
Array
<
{
:
unknown
[
]
}
>
;
.
deepStrictEqual
(
.
map
(
=>
.
)
,
[
[
]
]
)
;
const
=
.
map
(
=>
.
)
.
find
(
=>
.
===
.
)
;
.
ok
(
,
'expected a changeset/statusChanged envelope from the fallback path'
)
;
}
)
;
}
)
;
suite
(
'computeUncommittedChangeset'
,
(
)
=>
{
test
(
'happy path: git returns diffs, state goes Ready with files, nothing persisted to the DB'
,
async
(
)
=>
{
const
=
new
SessionDatabase
(
':memory:'
)
;
.
add
(
toDisposable
(
(
)
=>
.
close
(
)
)
)
;
const
=
createSessionDataService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
[
{
:
{
:
'file:///wd/a.ts'
,
:
{
:
'file:///wd/a.ts'
}
}
,
:
{
:
1
,
:
0
}
}
,
{
:
{
:
'file:///wd/b.ts'
,
:
{
:
'file:///wd/b.ts'
}
}
,
:
{
:
2
,
:
1
}
}
,
]
;
const
=
{
computeSessionFileDiffs
:
async
(
)
=>
,
}
as
unknown
as
;
const
=
.
add
(
new
TestAgentHostChangesetService
(
,
new
NullLogService
(
)
,
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
)
,
NULL_REVIEW_SERVICE
,
)
)
;
const
=
.
toString
(
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///wd'
]
,
}
)
;
await
.
computeUncommittedChangeset
(
)
;
const
=
`${sessionStr}/changeset/uncommitted`
;
const
=
.
getSnapshot
(
)
;
const
=
?.
as
{
:
string
;
:
Array
<
{
:
string
}
>
}
|
undefined
;
.
deepStrictEqual
(
{
:
?.
,
:
?.
.
map
(
=>
.
)
.
sort
(
)
,
:
await
.
getMetadata
(
'agentHost.changeset.uncommitted'
)
,
}
,
{
:
.
,
:
[
'file:///wd/a.ts'
,
'file:///wd/b.ts'
]
,
:
undefined
,
}
)
;
}
)
;
test
(
'no working directory: state goes Error with computeFailed'
,
async
(
)
=>
{
const
=
.
toString
(
)
;
setupSession
(
)
;
await
.
computeUncommittedChangeset
(
)
;
const
=
`${sessionStr}/changeset/uncommitted`
;
const
=
.
getSnapshot
(
)
;
const
=
?.
as
{
:
string
;
?
:
{
:
string
}
}
|
undefined
;
.
deepStrictEqual
(
{
:
?.
,
:
?.
?.
,
}
,
{
:
.
,
:
'computeFailed'
,
}
)
;
}
)
;
test
(
'git returns undefined (not a git work tree): state goes Error with computeFailed'
'recomputes an uncommitted subscription added after worktree pending clears but before materialization'
,
async
(
)
=>
{
const
=
.
uri
(
'mock'
,
'session-materialization'
)
.
toString
(
)
;
const
=
'file:///repo/source'
;
const
=
'file:///repo/worktree'
;
const
:
string
[
]
=
[
]
;
const
=
createNoopGitService
(
)
;
.
computeSessionFileDiffs
=
async
=>
{
.
push
(
.
toString
(
)
)
;
return
[
]
;
}
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
new
TestDiffComputeService
(
)
;
class
TestableChangesetService
extends
TestAgentHostChangesetService
{
protected
_createDiffComputeService
(
)
{
return
;
}
}
const
=
createSubscriptionService
(
)
;
const
=
.
add
(
new
TestableChangesetService
(
,
new
NullLogService
(
)
,
createNullSessionDataService
(
)
,
,
NULL_CHECKPOINT_SERVICE
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
,
NULL_REVIEW_SERVICE
,
,
)
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
]
,
}
,
{
:
false
}
)
;
const
=
buildUncommittedChangesetUri
(
)
;
.
addSubscription
(
,
)
;
await
.
computeUncommittedChangeset
(
)
;
const
=
.
getSessionSummary
(
)
!
;
.
markSessionPersisted
(
,
{
...
,
:
[
]
}
)
;
.
onWorkingDirectoryAvailable
(
)
;
await
timeout
(
0
)
;
.
deepStrictEqual
(
,
[
,
]
)
;
}
)
;
}
)
;
/**
* A log service that records every warning/error message so multi-root tests
* can assert the never-hard-fail path logged the expected per-folder failure.
*/
'marks a ready turn changeset as computing until recomputation completes'
,
async
(
)
=>
{
const
=
new
DeferredPromise<void>
(
)
;
let
=
0
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
.
computeFileDiffsBetweenRefs
=
async
(
)
=>
{
++
;
if
(
>
1
)
{
await
.
;
}
return
[
]
;
}
;
const
:
=
{
...
NULL_CHECKPOINT_SERVICE
,
getTurnCheckpointPair
:
async
(
)
=>
(
{
:
'parent'
,
:
'current'
}
)
,
}
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
new
TestDiffComputeService
(
)
;
class
TestableChangesetService
extends
TestAgentHostChangesetService
{
protected
_createDiffComputeService
(
)
{
return
;
}
}
const
=
.
add
(
new
TestableChangesetService
(
,
new
NullLogService
(
)
,
createSessionDataService
(
new
TestSessionDatabase
(
)
)
,
,
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
)
,
NULL_REVIEW_SERVICE
,
,
)
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
[
'file:///repo'
]
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
?.
;
.
complete
(
)
;
await
;
.
deepStrictEqual
(
{
,
:
.
getChangesetState
(
)
,
}
,
{
:
.
,
:
{
:
.
,
:
[
]
,
}
,
}
)
;
}
)
;
}
)
;
/**
* Multi-root turn changeset aggregation (AC-2). A separate top-level suite so
* these run against the current service (the older `AgentHostChangesetService`
* suite above is skipped pending an unrelated catalogue refresh).
*/
/** Builds a checkpoint service whose per-repo pair is derived from the working directory. */
function
makeCheckpoint
(
pairFor
:
(
:
string
|
undefined
)
=>
{
:
string
;
:
string
}
|
undefined
)
:
{
return
{
...
NULL_CHECKPOINT_SERVICE
,
getTurnCheckpointPair
:
async
(
:
URI
,
:
string
,
?
:
URI
)
=>
pairFor
(
?.
toString
(
)
)
,
}
;
}
function
build
(
:
{
:
string
[
]
;
:
;
:
;
?
:
;
?
:
;
?
:
;
?
:
string
[
]
;
?
:
{
:
string
;
:
;
:
string
;
?
:
(
)
=>
void
}
;
}
)
:
{
:
;
:
;
:
}
{
const
=
.
??
new
RecordingLogService
(
)
;
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
.
??
new
TestSessionDatabase
(
)
;
// The production diff-count worker runs an ESM module in a raw
// worker_thread, which the unit-test harness cannot load, so substitute
// the shared synchronous in-process computer via the factory seam.
const
=
new
TestDiffComputeService
(
)
;
class
TestableChangesetService
extends
TestAgentHostChangesetService
{
protected
_createDiffComputeService
(
)
{
return
;
}
}
const
=
createSessionDataService
(
)
;
const
=
.
?
createSessionDataService
(
.
.
)
:
undefined
;
const
=
.
add
(
new
TestableChangesetService
(
,
,
{
...
,
openDatabase
:
=>
{
if
(
.
?.
!==
.
toString
(
)
)
{
return
.
openDatabase
(
)
;
}
const
=
!
.
openDatabase
(
)
;
return
{
:
.
,
dispose
:
(
)
=>
{
.
?.
?.
(
)
;
.
dispose
(
)
;
}
,
}
;
}
,
}
,
.
,
.
,
.
add
(
new
AgentConfigurationService
(
,
new
NullLogService
(
)
)
)
,
createOperationService
(
)
,
createSubscriptionService
(
...
(
.
??
[
]
)
)
,
NULL_REVIEW_SERVICE
,
.
??
,
)
)
;
.
createSession
(
{
:
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
)
.
toISOString
(
)
,
:
new
Date
(
)
.
toISOString
(
)
,
:
.
,
}
)
;
if
(
.
)
{
.
addChat
(
,
.
.
)
;
.
dispatchServerAction
(
.
.
,
{
:
.
,
:
.
.
,
:
new
Date
(
0
)
.
toISOString
(
)
,
:
{
:
'peer'
,
:
{
:
.
}
}
,
}
)
;
.
dispatchServerAction
(
.
.
,
{
:
.
,
:
.
.
,
:
1
,
}
)
;
}
return
{
,
,
}
;
}
test
(
'aggregates turn diffs across all folders of a multi-root session'
,
async
(
)
=>
{
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
.
computeFileDiffsBetweenRefs
=
async
=>
{
const
=
.
toString
(
)
;
if
(
===
'file:///repoA'
)
{
return
[
gitDiff
(
'/repoA/a.ts'
)
]
;
}
if
(
===
'file:///repoB'
)
{
return
[
gitDiff
(
'/repoB/b.ts'
)
]
;
}
return
undefined
;
}
;
const
=
makeCheckpoint
(
=>
(
{
:
`${root}~p`
,
:
`${root}~c`
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repoA'
,
'file:///repoB'
]
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
)
;
.
deepStrictEqual
(
new
Set
(
?.
.
map
(
=>
.
)
)
,
new
Set
(
[
URI
.
file
(
'/repoA/a.ts'
)
.
toString
(
)
,
URI
.
file
(
'/repoB/b.ts'
)
.
toString
(
)
]
)
,
'the turn changeset must contain files from every folder'
,
)
;
}
)
;
test
(
'partitions git vs non-git folders so git-folder edits are not double-counted by the DB'
,
async
(
)
=>
{
const
=
new
TestSessionDatabase
(
)
;
// The DB edit tracker is path-based (no folder column) so it records
// edits from BOTH folders, including two under the git-backed repoB.
.
addEdit
(
{
:
'turn-1'
,
:
'tcX'
,
:
'/folderA/x.txt'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'a'
)
,
:
encodeString
(
'a\nb'
)
}
)
;
.
addEdit
(
{
:
'turn-1'
,
:
'tcY'
,
:
'/repoB/y.txt'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'c'
)
,
:
encodeString
(
'c\nd'
)
}
)
;
.
addEdit
(
{
:
'turn-1'
,
:
'tcZ'
,
:
'/repoB/z.txt'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'e'
)
,
:
encodeString
(
'e\nf'
)
}
)
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
.
toString
(
)
===
'file:///repoB'
?
URI
.
parse
(
'file:///repoB'
)
:
undefined
;
// git reports only y.txt for repoB (not z.txt) — if the DB partition
// leaked git-folder edits, z.txt would wrongly appear.
.
computeFileDiffsBetweenRefs
=
async
(
)
=>
[
gitDiff
(
'/repoB/y.txt'
,
2
,
0
)
]
;
const
=
makeCheckpoint
(
(
)
=>
(
{
:
'p'
,
:
'c'
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///folderA'
,
'file:///repoB'
]
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
)
;
const
=
!
.
.
map
(
=>
.
)
;
.
deepStrictEqual
(
[
...
]
.
sort
(
)
,
[
URI
.
file
(
'/folderA/x.txt'
)
.
toString
(
)
,
URI
.
file
(
'/repoB/y.txt'
)
.
toString
(
)
]
.
sort
(
)
,
'non-git folderA comes from the DB; repoB comes from git only (no leaked z.txt)'
,
)
;
.
strictEqual
(
.
filter
(
=>
===
URI
.
file
(
'/repoB/y.txt'
)
.
toString
(
)
)
.
,
1
,
'the git-backed file must appear exactly once'
,
)
;
}
)
;
test
(
'uses the owning peer database for multi-root non-git fallback'
,
async
(
)
=>
{
const
=
new
TestSessionDatabase
(
)
;
const
:
string
[
]
=
[
]
;
class
DelayedPeerDatabase
extends
TestSessionDatabase
{
async
getFileEditsByTurn
(
:
string
)
{
await
timeout
(
0
)
;
.
push
(
'read'
)
;
return
super
.
getFileEditsByTurn
(
)
;
}
}
const
=
new
DelayedPeerDatabase
(
)
;
.
addEdit
(
{
:
'peer-turn'
,
:
'tc1'
,
:
'/folderA/peer.txt'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'a'
)
,
:
encodeString
(
'a\nb'
)
}
)
;
const
=
'ahp-chat://peer-1/session-mr'
;
const
{
,
}
=
build
(
{
:
[
'file:///folderA'
,
'file:///folderB'
]
,
:
createNoopGitService
(
)
,
:
NULL_CHECKPOINT_SERVICE
,
:
,
:
{
:
,
:
,
:
'peer-turn'
,
onDispose
:
(
)
=>
.
push
(
'dispose'
)
}
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'peer-turn'
)
;
.
deepStrictEqual
(
{
:
.
getChangesetState
(
)
?.
.
map
(
=>
.
)
,
,
}
,
{
:
[
URI
.
file
(
'/folderA/peer.txt'
)
.
toString
(
)
]
,
:
[
'read'
,
'dispose'
]
,
}
)
;
}
)
;
test
(
'diffs a repository shared by two working directories exactly once (dedup by repo root)'
,
async
(
)
=>
{
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
(
)
=>
URI
.
parse
(
'file:///repo'
)
;
let
=
0
;
.
computeFileDiffsBetweenRefs
=
async
(
)
=>
{
++
;
return
[
gitDiff
(
'/repo/shared.ts'
)
]
;
}
;
const
=
makeCheckpoint
(
(
)
=>
(
{
:
'p'
,
:
'c'
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repo'
,
'file:///repo/sub'
]
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
.
strictEqual
(
,
1
,
'the shared repository is diffed exactly once'
)
;
const
=
.
getChangesetState
(
)
;
.
deepStrictEqual
(
?.
.
map
(
=>
.
)
,
[
URI
.
file
(
'/repo/shared.ts'
)
.
toString
(
)
]
)
;
}
)
;
test
(
'keeps the turn changeset ready and logs an error when one folder git diff throws'
,
async
(
)
=>
{
const
=
new
RecordingLogService
(
)
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
.
computeFileDiffsBetweenRefs
=
async
=>
{
if
(
.
toString
(
)
===
'file:///repoBad'
)
{
throw
new
Error
(
'git exploded'
)
;
}
return
[
gitDiff
(
'/repoGood/g.ts'
)
]
;
}
;
const
=
makeCheckpoint
(
=>
(
{
:
`${root}~p`
,
:
`${root}~c`
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repoBad'
,
'file:///repoGood'
]
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
,
'one folder failure must not error the whole changeset'
)
;
.
deepStrictEqual
(
?.
.
map
(
=>
.
)
,
[
URI
.
file
(
'/repoGood/g.ts'
)
.
toString
(
)
]
)
;
.
ok
(
.
.
some
(
=>
.
includes
(
'repoBad'
)
)
,
`expected an error naming the failing repository, got ${JSON.stringify(log.errors)}`
)
;
}
)
;
test
(
'a git repository whose turn diff fails falls back to that folder\'s DB edits'
,
async
(
)
=>
{
const
=
new
RecordingLogService
(
)
;
const
=
new
TestSessionDatabase
(
)
;
// repoBad is git-backed but its git turn diff throws; the edit under it is
// tracked only in the path-based DB, so the per-folder DB fallback must
// surface it instead of the folder being dropped.
.
addEdit
(
{
:
'turn-1'
,
:
'tcBad'
,
:
'/repoBad/x.ts'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'a'
)
,
:
encodeString
(
'a\nb'
)
}
)
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
.
computeFileDiffsBetweenRefs
=
async
=>
{
if
(
.
toString
(
)
===
'file:///repoBad'
)
{
throw
new
Error
(
'git exploded'
)
;
}
return
[
gitDiff
(
'/repoGood/g.ts'
)
]
;
}
;
const
=
makeCheckpoint
(
=>
(
{
:
`${root}~p`
,
:
`${root}~c`
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repoBad'
,
'file:///repoGood'
]
,
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
)
;
.
deepStrictEqual
(
[
...
!
.
.
map
(
=>
.
)
]
.
sort
(
)
,
[
URI
.
file
(
'/repoBad/x.ts'
)
.
toString
(
)
,
URI
.
file
(
'/repoGood/g.ts'
)
.
toString
(
)
]
.
sort
(
)
,
'the failed git repo contributes its DB-tracked edits instead of dropping the folder'
,
)
;
.
ok
(
.
.
some
(
=>
.
includes
(
'repoBad'
)
&&
.
includes
(
'falling back to tracked edits'
)
)
,
`expected a fallback error naming the repo, got ${JSON.stringify(log.errors)}`
)
;
}
)
;
test
(
'missing checkpoint refs use tracked edits without logging an error'
,
async
(
)
=>
{
const
=
new
RecordingLogService
(
)
;
const
=
new
TestSessionDatabase
(
)
;
.
addEdit
(
{
:
'turn-1'
,
:
'tc1'
,
:
'/repoA/tracked.ts'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'1'
)
,
:
encodeString
(
'1\n2'
)
}
)
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repoA'
,
'file:///repoB'
]
,
,
:
makeCheckpoint
(
(
)
=>
undefined
)
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
.
deepStrictEqual
(
{
:
.
getChangesetState
(
)
?.
,
:
.
getChangesetState
(
)
?.
.
map
(
=>
.
)
,
:
.
,
}
,
{
:
.
,
:
[
URI
.
file
(
'/repoA/tracked.ts'
)
.
toString
(
)
]
,
:
[
]
,
}
)
;
}
)
;
test
(
'a folder whose repository-root lookup throws is treated as non-git (DB fallback) without dropping the whole turn'
,
async
(
)
=>
{
const
=
new
RecordingLogService
(
)
;
const
=
new
TestSessionDatabase
(
)
;
// repoBad's ROOT resolution fails (not its git diff). Its edit is tracked
// only in the path-based DB, so it must surface via the non-git fallback
// while repoGood still contributes its git diff — before Issue 10 a single
// root-resolution failure dropped the WHOLE turn to an empty changeset.
.
addEdit
(
{
:
'turn-1'
,
:
'tcBad'
,
:
'/repoBad/x.ts'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'a'
)
,
:
encodeString
(
'a\nb'
)
}
)
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
{
if
(
.
toString
(
)
===
'file:///repoBad'
)
{
throw
new
Error
(
'rev-parse exploded'
)
;
}
return
URI
.
parse
(
.
toString
(
)
)
;
}
;
.
computeFileDiffsBetweenRefs
=
async
(
)
=>
[
gitDiff
(
'/repoGood/g.ts'
)
]
;
const
=
makeCheckpoint
(
=>
(
{
:
`${root}~p`
,
:
`${root}~c`
}
)
)
;
const
{
,
}
=
build
(
{
:
[
'file:///repoBad'
,
'file:///repoGood'
]
,
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
deepStrictEqual
(
{
:
?.
,
:
[
...
!
.
.
map
(
=>
.
)
]
.
sort
(
)
,
:
.
.
some
(
=>
.
includes
(
'repoBad'
)
)
,
}
,
{
:
.
,
:
[
URI
.
file
(
'/repoBad/x.ts'
)
.
toString
(
)
,
URI
.
file
(
'/repoGood/g.ts'
)
.
toString
(
)
]
.
sort
(
)
,
:
true
,
}
,
'the failed-root folder falls back to its DB edits; the healthy folder is unaffected'
)
;
}
)
;
test
(
'multi-folder turn diffs fan out over every repository with bounded concurrency and no cap'
,
async
(
)
=>
{
const
=
new
RecordingLogService
(
)
;
const
=
25
;
const
=
Array
.
from
(
{
:
}
,
(
,
)
=>
`file:///repo${i}`
)
;
const
:
string
[
]
=
[
]
;
let
=
0
;
let
=
0
;
const
:
Array
<
(
)
=>
void
>
=
[
]
;
const
=
createNoopGitService
(
)
;
.
getRepositoryRoot
=
async
=>
URI
.
parse
(
.
toString
(
)
)
;
// Each diff parks on its own gate so we can observe how many run at once.
.
computeFileDiffsBetweenRefs
=
async
=>
{
.
push
(
.
toString
(
)
)
;
++
;
=
.
max
(
,
)
;
await
new
Promise<void>
(
=>
.
push
(
(
)
=>
{
--
;
resolve
(
)
;
}
)
)
;
return
[
]
;
}
;
const
=
makeCheckpoint
(
=>
(
{
:
`${root}~p`
,
:
`${root}~c`
}
)
)
;
const
{
,
}
=
build
(
{
,
,
,
}
)
;
const
=
.
computeTurnChangeset
(
,
'turn-1'
)
;
// With every diff gated, only the concurrency limit start at once; the
// rest stay queued in the limiter (they are not dropped).
for
(
let
=
0
;
<
500
&&
.
<
5
;
++
)
{
await
timeout
(
1
)
;
}
await
timeout
(
10
)
;
// give a (wrongly) unbounded 6th diff a chance to start
const
=
.
;
// Release the gated diffs one at a time, yielding so the limiter starts
// the next queued diff, until the whole turn compute settles.
let
=
false
;
void
.
then
(
(
)
=>
{
=
true
;
}
)
;
while
(
!
)
{
.
shift
(
)
?.
(
)
;
await
timeout
(
0
)
;
}
const
=
await
;
.
deepStrictEqual
(
{
,
,
:
.
,
:
.
.
some
(
=>
.
includes
(
'capping'
)
)
,
:
.
getChangesetState
(
)
?.
,
}
,
{
:
5
,
:
5
,
:
,
:
false
,
:
.
,
}
)
;
}
)
;
test
(
'single-folder checkpoint path is byte-for-byte unchanged'
,
async
(
)
=>
{
const
:
Array
<
{
:
string
;
:
string
|
undefined
}
>
=
[
]
;
const
:
=
{
...
NULL_CHECKPOINT_SERVICE
,
getTurnCheckpointPair
:
async
(
:
URI
,
:
string
,
?
:
URI
)
=>
{
.
push
(
{
,
:
?.
toString
(
)
}
)
;
return
{
:
'p'
,
:
'c'
}
;
}
,
}
;
const
=
createNoopGitService
(
)
;
let
=
0
;
.
getRepositoryRoot
=
async
(
)
=>
{
++
;
return
undefined
;
}
;
const
:
Array
<
{
:
string
;
:
string
;
:
string
}
>
=
[
]
;
.
computeFileDiffsBetweenRefs
=
async
(
,
)
=>
{
.
push
(
{
:
.
toString
(
)
,
:
.
,
:
.
}
)
;
return
[
gitDiff
(
'/wd/only.ts'
)
]
;
}
;
const
{
,
}
=
build
(
{
:
[
'file:///wd'
]
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
)
;
.
deepStrictEqual
(
?.
.
map
(
=>
.
)
,
[
URI
.
file
(
'/wd/only.ts'
)
.
toString
(
)
]
)
;
.
strictEqual
(
,
0
,
'single-folder path must not resolve per-folder repositories'
)
;
.
deepStrictEqual
(
,
[
{
:
'turn-1'
,
:
undefined
}
]
,
'checkpoint pair is requested session-wide, not per-repo'
)
;
.
deepStrictEqual
(
,
[
{
:
'file:///wd'
,
:
'p'
,
:
'c'
}
]
)
;
}
)
;
test
(
'single-folder DB fallback path is byte-for-byte unchanged'
,
async
(
)
=>
{
const
=
new
TestSessionDatabase
(
)
;
.
addEdit
(
{
:
'turn-1'
,
:
'tc1'
,
:
'/wd/tracked.ts'
,
:
.
,
:
undefined
,
:
undefined
,
:
encodeString
(
'1'
)
,
:
encodeString
(
'1\n2'
)
}
)
;
const
:
=
{
...
NULL_CHECKPOINT_SERVICE
,
getTurnCheckpointPair
:
async
(
)
=>
undefined
}
;
const
=
createNoopGitService
(
)
;
let
=
0
;
.
getRepositoryRoot
=
async
(
)
=>
{
++
;
return
undefined
;
}
;
const
{
,
}
=
build
(
{
:
[
'file:///wd'
]
,
,
,
}
)
;
const
=
await
.
computeTurnChangeset
(
,
'turn-1'
)
;
const
=
.
getChangesetState
(
)
;
.
strictEqual
(
?.
,
.
)
;
.
deepStrictEqual
(
?.
.
map
(
=>
.
)
,
[
URI
.
file
(
'/wd/tracked.ts'
)
.
toString
(
)
]
,
'fallback returns all of the turn edits, exactly as today'
)
;
.
strictEqual
(
,
0
,
'single-folder fallback must not resolve repositories'
)
;
}
)
;
/**
* All-folder branch summary (AC-3). In a multi-folder session the
* `summary.changes` chip must reflect EVERY folder's branch delta, computed
* independently of the primary-only branch changeset, and must survive a
* subsequent branch recompute. Single-folder sessions stay branch-derived
* (byte-for-byte unchanged).
*/
suite
(
'all-folder branch summary'
,
(
)
=>
{
/** Polls until the live session summary carries a `changes` aggregate. */
async
function
waitForSummaryChanges
(
:
)
:
Promise
<
|
undefined
>
{
for
(
let
=
0
;
<
500
;
++
)
{
const
=
.
getSessionSummary
(
)
?.
;
if
(
)
{
return
;
}
await
timeout
(
1
)
;
}
return
.
getSessionSummary
(
)
?.
;
}
/** Polls until `count()` reaches (at least) `target`. */
async
function
waitForCount
(
count
:
(
)
=>
number
,
:
number
)
:
Promise
<
void
>
{
for
(
let
=
0
;
<
500
&&
count
(
)
<
;
++
)
{
await
timeout
(
1
)
;
}
}
test
(
'sums every repository branch diff, not just the primary'