mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
* feat(dsh): add Environment tab with local Python detection
Adds a read-only Environment tab to the ReMe Memory settings card so
users can see why the ReMe service is unreachable before touching a
terminal:
- discover local Python interpreters via the PEP 514 registry, py
launcher, PATH and conda (base + named envs), then verify every
candidate by actually running it
- classify origins (conda base/env, python.org, Microsoft Store, venv,
system PATH), drop Store alias stubs, and suggest a preferred
interpreter (Python >= 3.11, named conda envs first)
- expose detection to the browser through a new remeEnv host gateway
(TypertRemoteService) and render it with a connection health check
- config gains optional authToken and pythonPath fields with unchanged
defaults; existing memory settings keep their behavior
Parsing is fixture-tested against real tool output on Windows (GBK
codepages, localized reg labels, missing py launcher) and Linux.
* feat(dsh): check and install reme-ai from the Environment tab
- check reme-ai version, the [core] AgentScope import and the reme CLI
for the selected interpreter; an outdated install is flagged instead
of treated as ready
- one-click pip install of reme-ai[core] as a Host job: per-job log file,
2s log-tail polling, cancel, and running-job restore after a page
reload; the optional mirror overrides pip only for that run
- interpreter detection now probes reme-ai per environment, so the
suggestion prefers a named conda env with a usable reme (an outdated
reme no longer outranks a ready environment)
- fix: DSH exposes these Remote methods in SRC mode, which parses the
method source; every method takes one plain `input` identifier
parameter (no defaults or destructuring) and the client sends
`{ args: { input } }`
* feat(dsh): manage ReMe .env settings from the Environment tab
- read the workspace .env as a masked projection: non-secret values are
editable, API keys return only •••• plus their last four characters
- merge edits into the existing file, preserving comments, ordering and
unknown variables; validate the effective file so an untouched real
key still satisfies the LLM requirement
- require a non-empty EMBEDDING_API_KEY (EMPTY placeholder fills in on
first save), because ReMe 0.4.0.x aborts startup without one
- test the configured LLM endpoint from inside the workspace with the
selected interpreter, classifying 401/404/network failures
- add the remeWorkspaceDir setting (empty means ~/.reme) consumed by
the .env editor and later service management
Real-machine check: masked read leaks no secret, temp-workspace write
is idempotent and rejects an empty embedding key, and the LLM probe
against the local ~/.reme/.env returned HTTP 200.
* feat(dsh): start and stop the local ReMe service
- service status combines a direct /health_check probe with port probing:
running (managed or foreign), port conflict, or stopped
- start composes `reme start` with an absolute workspace_dir and
service.host/port, runs it detached inside the workspace (so ReMe's
.env discovery works), injects UTF-8 and NO_PROXY, disables the rich
logo, and only passes jobs.dream_cron.enabled=false on reme >= 0.4.1
- the plugin records the PID and launch arguments in service.json, so
stop can tree-kill the managed process; foreign instances are shown
but not touched
- serviceLog exposes the workspace log tail for start-failure diagnosis
- optional autoStart setting starts a stopped local service when DSH
boots, using the selected interpreter (or the detected suggestion)
Real-machine check: started ReMe 0.4.0.9 on port 2334 in a temp
workspace, observed running/managed with the recorded PID, then
stopped it and confirmed the port was released.
* docs(dsh): document the environment management tab
Describe the five Environment sections, the .env and EMBEDDING_API_KEY
contracts, local service control semantics, and the optional authToken
field in both READMEs.
* fix(dsh): mount the environment gateway under its own service key
TypertRemoteService registers itself under the constructor key, so
`super(ctx, remeEnv)` collided with the already-provided `remeEnv`
manager: the gateway plugin failed activation (its async rejection was
logged only), leaving every /api/remeEnv/* call with HTTP 404.
Register the service as `remeEnvGateway` and keep the wire namespace
`remeEnv`, which is what the client calls. Add a real-cordis regression
test that mounts the gateway inside the same isolated realm and asserts
the binding, the namespace, and the SRC-parsed `input` parameter.
Also show the interpreter hint on detection failure so an empty list
never leaves the tab without guidance.
* feat(dsh): restructure the environment tab for scanability
The environment tab rendered as one flat column: five identical headings,
every detected interpreter in one long list, and the whole .env form
always expanded. That reads like prose and grows without bound on
machines with dozens of conda environments.
- Lead with a status hero (endpoint, service/Python/ReMe chips, retest and
rescan) so the current state is readable at a glance.
- Turn the four remaining groups into numbered cards with a status pill in
the header, so setup order and per-step state are obvious.
- Show only the interpreter in use, then reveal the rest on demand:
search box, six rows per page, and a show-all toggle.
- Collapse the .env editor behind a summary line (path + model).
- Explain the "recommended" marker through a tooltip; the flag now also
distinguishes an outdated reme-ai (amber) from a current one.
- Expose versionOk on the detection probe so the client can tone the tag
without importing host-only modules.
- Add a react-test-renderer suite covering the hero, card count, collapsed
list, pagination and interpreter selection.
* docs(dsh): format README tables with prettier
Table column padding in both READMEs did not match prettier's output, so the plugin CI format check failed. Content is unchanged.
* test(dsh): stub the health probe in the environment tab test
The tab renders a hero from /health_check on mount. The test asserted the ready state, which only held while a local ReMe service was running, so it failed on CI runners. Replace global fetch with a canned health response for the duration of each test.
* chore(dsh): target DSH 0.2.2-alpha.2
Add the current DSH release to the peer ranges and to the package
compatibility matrix (cordis 4.0.6-alpha.1, loader 1.0.7-alpha.1,
schemastery 3.18.6-alpha.1), which needs Node 24.9 or newer.
The packaged-plugin check now launches the npm CLI through node using
the npm_execpath npm exports, so it also runs on Windows where npm is
npm.cmd and execFile cannot start it.
* refactor(dsh): collect environment management under src/environment
Move the Host modules out of src/pyenv and the tab out of src/client so
the feature has one boundary:
src/environment/types.ts browser-safe RPC contract
src/environment/host/*.ts detection, install, service, workspace
src/environment/client/* the Environment tab
src/environment/host/gateway remeEnv RPC surface
src/environment/host/manager the operations the gateway exposes
The cross-boundary shapes (detection, reme-ai check, install job, .env
summary, service state) now live in one browser-safe module instead of
being pulled from Host modules that import node built-ins; Host-only
shapes stay beside the code that owns them. src/index.ts registers the
gateway and manager, src/client/index.tsx mounts the tab. The wire
namespace, method names and service keys are unchanged.
* refactor(dsh): split the environment tab into per-section modules
The tab was one 2,213-line component with 27 state hooks. It is now one
module per step, and each step owns the asynchronous state it shows:
client/tab.tsx layout, hero, the settings reads
client/python.tsx usePython + the interpreter section
client/dependency.tsx useDependency + the reme-ai section
client/workspace.tsx useWorkspace + the .env section
client/service.tsx useService/useHealth + the service section
client/presentation shared badges, tags and field frames
client/rpc.ts the remeEnv calls and their response guards
client/locales.ts the tab's copy
client/styles.ts the tab's CSS
The .env controls now come from one field table, and the stylesheet split
keeps the tab's CSS next to the tab.
State is keyed where the review asked for it: install progress carries the
job id it polls and cancels, workspace drafts and in-flight saves carry the
workspace they were typed for, and a check result only shows for the
interpreter it belongs to. Drafts also distinguish untouched fields from
explicit clears, so emptying a non-secret field now clears it on disk. The
memory settings draft parser no longer carries the environment fields
through, since saving only writes this page's FIELDS list.
* fix(dsh): probe from the Host and bound every process lifetime
Local now means the DSH Host everywhere. The tab no longer fetches the
service URL from the browser: the hero reads the same Host probe the
service card uses, and a remote endpoint is probed through a new
remeEnv/health method, so a browser on another machine cannot disagree
with the Host. The wire namespace, method parameter convention and
service keys are unchanged.
Process lifetimes are explicit and documented in the manager. Python
probes and reme-ai checks stay bounded one-shot commands. pip installs
live in the manager's registry, keep the interpreter locked between a
cancel request and the actual exit, and are stopped by dispose() when
the plugin unloads. The ReMe service stays detached on purpose: it must
outlive DSH, so it is not handed to DSH's subprocess provider, which
kills its children on Host exit; it is stopped only through the
ownership-checked adapter in service.ts.
That adapter now verifies identity before reporting or stopping a
service: the recorded endpoint must match, the pid must be alive, and
its image must still be Python or reme, which protects against pid
reuse. A launch is recorded only after the OS acknowledged the spawn,
and a spawn failure returns an error instead of an unhandled event.
Starts are serialized and re-check the phase inside the lock, so two
requests cannot spawn two services. Health answers are validated, so a
generic HTTP server answering 200 with '{}' is no longer reported as a
running ReMe service, and authToken now rides the Authorization header
of both the client requests and the Host probe.
.env merging rewrites every occurrence of a key (parsing keeps the last
one), keeps the file's line ending, and validates the merged file rather
than just the submitted values.
* docs(dsh): move environment setup into dedicated guides
The two READMEs keep a short introduction to the Environment tab and link
to docs/environment.md / docs/environment_ZH.md, which now carry the
setup and troubleshooting detail: Python and conda discovery plus the
recommendation rule, dependency installation, .env validation and
clearing, connection testing, the detached service lifetime, platform
support and the failure modes of each step.
The version lists include 0.2.2-alpha.2 and note that current DSH needs
Node 24.9 or newer. The package now ships docs/ as well, so the guide
travels with the published plugin.
* fix(dsh): resolve interpreter paths with their own platform semantics
The interpreter helpers mixed simulated-platform knowledge with the host's
node:path, so Windows fixtures only resolved on Windows: on macOS and
Linux condaRootFromPath, pathContains, pythonPrefix, classifyOrigin,
remeCliPath and the pip path check all fell back to POSIX semantics and
nine tests failed.
Paths now carry their flavor: pathOf() picks win32 or posix from the value
itself, and the functions that already know the simulated platform use it
explicitly. Behaviour on Windows is unchanged; the same fixtures now
resolve identically on every host, which the new tests assert for both
flavors.
* refactor(dsh): stage the settings card with DSH's form model
The memory settings card carried its own draft state machine: a Draft
object, a parser that re-validated every field, a hand-written diff into
path operations, and its own revision fence. DSH ships exactly that as
SettingsFormModel, exported by the primitives package this plugin already
depends on and injects since 0.1.7-rc.2.
The card now builds the model once, reads shell()/field() while rendering
and hands every edit to actions(), so what is left is the controls plus
one field-spec table in settings-specs.ts. The revision fence, the
dirty/invalid/saving/failed states, keeping drafts after a refused save,
and clearing only the fields the user layer carries all come from the
model.
The one visible change: reset now stages clears for the fields the user
layer actually overrides, which is what that control always meant.
Tests: settings-specs.test.mjs covers every spec on its own, and the card
test runs DSH's real SettingsFormModel (evaluated from the installed
primitives bundle, which cannot be imported in Node because it loads CSS
modules and icons). The packaged-plugin check exercises that against all
six supported DSH releases.
* test(dsh): pin the plugin lifetime that stops install jobs
dispose() on the manager stops running installs, but nothing tied that to
the plugin's own lifetime: a change to the registration could have left
pip running after the plugin unloads. Mount the plugin, replace the
provided manager's dispose with a counter, run the envLifetime cleanup and
assert it is called once.
* fix(dsh): harden environment management from review
- wire the package mirror into installs
- wait for service exit, escalate to SIGKILL, keep the record on failure
- fail closed on ownership and clear dead service records
- clear the start lock on failure and reject overlapping starts
- bound probes, make config writes atomic, scope auth tokens
- fix docs and add regression tests
* fix(dsh): verify service identity before touching a recorded pid
- require command-line evidence for owned service processes
- discard unprovable stale records instead of blocking startup
- identify and stop our own unhealthy conflict; serialize stop with start
- reject IPv6 loopback endpoints
- rotate oversized logs and fix tailing multibyte cuts
- add tests for env writes, client failures and real spawner
* fix(dsh): finish the environment review follow-ups
- match escaped wrapper command lines when proving service ownership
- reset aborted LLM probes and consume stopped/conflict start signals
- abort start polling on endpoint switch and guard stale service state
- force --force-reinstall for Reinstall; localize start/stop reasons
- validate rendered RPC fields, prune install logs and polish UI states
* fix(dsh): address the environment review on 603ea41
* fix(dsh): close the stale-service and probe follow-ups
* fix(dsh): let an unverifiable service record be forgotten
* fix(dsh): close the install, record and LLM probe follow-ups
- re-check reme-ai after a successful install, so the dependency card and
Start follow the install instead of waiting for a manual Check
- bind every install answer to the interpreter that asked for it and to a
request generation, and restore the running job of the selected
interpreter rather than the globally latest one
- let the Host name the record that blocked a start or a stop, and aim the
confirmed Forget at that record, pinned by its pid so a record that
changed meanwhile is refused instead of dropped
- probe the LLM with the protocol of the selected backend, including the
providers whose credentials ignore LLM_BASE_URL
- extract the manager's service queue and its common start-failure result
- supply the timer globals in the settings test harness so the React
cleanup runs cleanly
* fix(dsh): align the LLM probe and the record recovery with ReMe
- probe the providers whose credentials ignore LLM_BASE_URL with their own
endpoint, so a stale value in the .env cannot report a working
configuration as broken
- build the request URL the way the provider's own SDK builds it, so a base
that already carries the version suffix fails in the probe exactly as it
fails in the service
- withdraw the Forget offer when the record changed instead of re-aiming
it at a record the user never saw, and name the process in the
confirmation
- compare interpreter paths with one shared key on both sides, so a job the
Host restored is not dropped again by the tab
- never poll an installation without a job id
* fix(dsh): probe xAI on its own endpoint and wait for a saved backend
- give xAI its own protocol: its credential carries an api host instead of
a base URL, so the probe no longer demands LLM_BASE_URL for a
configuration ReMe accepts
- say that the xAI probe is a REST-level approximation of the gRPC SDK
ReMe uses for that provider
- hold the LLM test back while the chosen backend is not saved, because the
probe reads the .env on disk
* chore: ignore the local CodeGraph index
The index is machine-local and rebuildable, so it must not show up as an
untracked file in every checkout.
* fix(dsh): gate the LLM test on every unsaved probe setting
- compare the model, the base URL and a typed key against the saved .env,
so the test never runs against a configuration the user did not put on
disk
- resolve an empty backend to the default on both sides, so picking the
default in the form is not treated as a change
- broaden the probe guard against a rewritten base URL
* fix(dsh): hold the install lock until the exit and keep pending .env edits
Addresses the four P2 findings of the review on c499cc0e.
Install lifecycle (host/install.ts)
- One shared termination path serves cancel() and dispose(): a graceful
signal first, then a force-kill after a bounded grace. No timer settles a
job any more - only an observed exit does - so a termination that could
not be confirmed stays visible as running/cancelling and keeps the
interpreter locked instead of reporting a completed cancellation.
- dispose() escalates without a grace period, so a pip that ignored
SIGTERM cannot outlive the Host.
- start() reuses runningFor(), so the lock is one lookup.
.env form (client/workspace.tsx, env-fields.ts)
- A save clears only the edits it submitted; a value typed while the save
was in flight keeps its newer value, and the saved message says that
edits are still pending.
- An emptied secret draft no longer travels: "leave blank to keep" holds
even after a replacement was typed and cleared, so the stored credential
survives and the other changes are saved. An emptied non-secret is still
an explicit clear.
- The managed keys, their secret flags and their update rules now live in
one browser-safe module that the Host and the tab both derive from; the
Host applies the same rules, so an older client cannot clear a secret.
Simplification
- The settings card reads the form model through model.bind() and
useSyncExternalStore, and shell.saving replaces the separate busy state
and the manual publish() calls.
- The Host health probe goes through ReMeClient, keeping its three-second
timeout and its localized codes, and now requires a parsable health
report instead of accepting health: {}.
- One predicate (environment/dependency.ts) decides what an interpreter can
host, so the Start button and the Host's start gate agree; the loopback
endpoint rules are shared too.
Tests: 247 plugin tests pass, plus the six-version package matrix.
* fix(dsh): keep a cancelled install locked until its process group is empty
The observed exit of the pip leader did not prove that its managed process group had exited: a build child that ignored the graceful signal could outlive it while the job was already reported as cancelled and the interpreter lock was released.
- The install child now reports whether its process group still holds a process (process.kill(-pid, 0) on POSIX; Windows starts no group and keeps using taskkill /T).
- When a cancelled leader exits while the group is still populated, the group is force-killed and the job stays running/cancelling until the group is empty. Only then does it settle as cancelled, so a second installation cannot race a build child that is still running.
- The wait is bounded; a group that never empties keeps the job unconfirmed and locked instead of reporting a cancellation that did not happen.
- Regression tests cover a leader that exits before its child and a group that never empties.
* fix(dsh): scope the workspace .env state to its directory
Switching workspaces aborted an in-flight probe but kept completed state: a save message and a successful LLM test from workspace A stayed on screen while the card showed workspace B (and named B's .env path).
- WorkspaceSection now owns useWorkspace; the tab mounts it with the workspace directory as its React key, so a switch disposes the previous drafts, read, save message and probe result instead of invalidating each one.
- Removed the repeated directory markers and stale-answer checks (Draft.dir, EnvState.entriesFor, latestDir); the section state simply belongs to one directory.
- Kept the pending-save protection (a save clears only the edits it carried, through the draft mirror) and made unmount cleanup explicit: the probe is aborted and a save that settles after unmount writes no state.
- Regression coverage drives the real section across a switch after a completed save and a successful probe, and the tab tests cover the draft and in-flight probe cases.
* fix(dsh): only offer local startup for root-path endpoints
parseLocalEndpoint accepted http://127.0.0.1:2333/reme, but the launch command configures only service.host and service.port: the started service answers at the origin root, so the subsequent health check at /reme/health_check would 404 and the launch would end in a conflict or a startup timeout.
- Reject a loopback endpoint whose path is not the origin root.
- A prefixed gateway URL is therefore not a manageable local service; it falls back to the remote health probe at its own path, which keeps connection testing (regression covered in the tab tests).
- The settings validator still accepts such a URL, so an existing gateway configuration keeps being probed.
* refactor(dsh): derive the settings and .env field definitions
Two pairs of definitions described the same fields and were kept aligned by hand.
Settings fields
- SETTINGS_SPECS is now the one definition: an internal const array checked against SettingsFieldSpec with 'as const satisfies', with generic helpers that keep every field name a string literal.
- SettingField and SETTING_FIELDS are derived from it, so the exported field-name union stays closed without a second hand-written list or an alignment test; SettingsFormModel receives a mutable copy, and the format/parse behaviour is unchanged.
.env fields
- The 'empty draft' rule of every managed key is derived from its secret flag, so EnvEmptyRule and the per-row setting are gone. A blank secret still means 'leave blank to keep'; a blank non-secret is still an explicit clear.
- disabledValue, storedState, the unknown-key passthrough and the shared Host/Client update function are unchanged.
* docs(dsh): describe the process-group, workspace and root-path rules
- A cancellation keeps the interpreter locked until the whole managed process group exits, and an unload watches the group too.
- The draft, the save message and the LLM-test result belong to their workspace; switching disposes them.
- Local startup is only offered for a loopback endpoint at the origin root; a prefixed gateway URL is health-probed as a remote one.
* fix(dsh): keep a legacy prefixed service record identifiable
Restricting local startup to root-path endpoints made the ownership check reject records written by an older version: commandMatches() reused parseLocalEndpoint() only to read the port, so a prefixed endpoint threw and a live, plugin-started process was reported as foreign. Start refused to launch it and Stop refused to own it, turning the record into an orphan.
- commandMatches() now reads the recorded port with a lenient parser instead of the launch rule, so a prefixed legacy record stays owned. Stop can then signal the recorded pid and clear the record once it exited.
- Regression test: a prefixed legacy record is recognized as owned, Stop is accepted, and the record is dropped after the exit.
* fix(dsh): explain why a prefixed endpoint is not managed locally
The remote notice said only that the URL is not local, which reads like a misconfiguration for a gateway mounted under a path prefix on the same machine. It now states that only the connection is probed and that a path-prefixed gateway cannot be managed locally.
* docs(dsh): note the process-group signalling limits
Record why a group that never empties stays unconfirmed, and that the group-id liveness probe counts an unreaped zombie and can take one extra poll; a pathological pid reuse around the leader's exit is inherent to signalling a process group.
* fix(dsh): replace a same-origin leftover service instead of refusing the start
After local startup was restricted to root-path endpoints, a service recorded by an older version under a same-origin path prefix (e.g. http://127.0.0.1:2334/reme) could not be reached from the tab: the prefixed endpoint hides the service card, and a start from the root endpoint was refused with 'stop it from that endpoint first', which the UI cannot do.
- serviceOriginKey() canonicalizes protocol/host/port (folded loopback aliases and default ports) without the path, next to the existing full endpoint key.
- A start now stops a provably owned record whose endpoint shares the origin of the requested one and continues; the launch configures only host and port, so both endpoints name the same local process. A record for another origin is still refused as before, with ownership/pid/image/command evidence unchanged.
- Manager-level regression: a leftover /reme record is stopped, the new launch is spawned, and its pid replaces the old record.
* docs(dsh): tighten the prefixed-endpoint notice and the group-poll note
- The remote notice now says 'not a loopback URL at the origin root', which reads as a rule rather than a misconfiguration.
- The install poll note states that an unreaped zombie keeps the group non-empty until it is reaped, instead of implying a single extra poll.
* fix(dsh): only replace a same-origin service when the request can launch
The same-origin replacement was symmetric: a request for a prefixed endpoint (which buildStartCommand refuses anyway) stopped a live root-path service under the same origin first, then failed to start anything. With autoStart enabled and a prefixed endpoint configured, every DSH start would kill the healthy detached service.
- The replacement branch now requires the requested endpoint to be launchable (a root-path loopback endpoint), the same rule buildStartCommand applies; otherwise the start is refused with the previous other-endpoint-running result and the service is left running.
- Regression: a prefixed request against a live same-origin root record must not killTree, must not spawn, and must leave the record intact.
* refactor(dsh): drop the unused derived settings field list
SETTING_FIELDS had no consumer once the field list was derived from SETTING_SPEC_DEFS; keeping the array around left a second list that looked like it still needed syncing. The closed SettingField union stays derived from the one table, and SettingsFormModel still receives a mutable copy of SETTINGS_SPECS.
* fix(dsh): skip auto-start for an endpoint that cannot launch
With autoStart enabled and a path-prefixed endpoint configured, DSH startup asked for a start that buildStartCommand must refuse, logging a warning on every start. autoStart now checks the same launchability rule first and returns without probing or starting, so a remote or prefixed endpoint is left to connection probing.
- Regression: auto-start does not probe a prefixed endpoint and spawns nothing, while a root-path endpoint still auto-starts.
* fix(dsh): adopt a same-origin leftover service record instead of orphaning it
A record left by an older version under a path prefix of the same origin
(`/reme`) describes the service the endpoint on screen talks to: the launch
configures only host and port. The record was nevertheless judged foreign,
because the ownership check compares the full endpoint key while the
same-origin replacement compares the origin.
The Host now re-keys such a record to the endpoint on screen, so the tab can
stop it and a start can replace it. The conflict branch falls back to the
same guard when the record could not be re-keyed. The adoption compares and
writes the record without yielding, so a launch that records its own pid
while the ownership probe runs is never overwritten.
* docs(dsh): describe how a leftover same-origin record is adopted
* docs(dsh): Fix markdown autolink over-capture
* test(dsh): cover the conflict fallback when the leftover cannot be re-keyed
The re-keying of a same-origin leftover is a write to the state file. When
that write fails, the record keeps naming the old endpoint and the conflict
branch has to fall back to the same guard, or the port stays occupied by our
own service and the tab has no way out.
* docs(dsh): keep the example endpoint out of the GUI's link renderer
The Web GUI renders a code span whose content is exactly an http(s) URL as a
clickable link inside the code chip, so the leftover endpoint example became
a link. The example is now written without its scheme, which no renderer
linkifies, and the space added by 2fc90233 (outside the code span, so it never
had any effect) is dropped again.
The guarantee is also narrowed to what the code does: a leftover record is
re-keyed when it can be proven to be this plugin's service.
* test(dsh): keep the user docs free of linkified code spans
* docs(dsh): state what the leftover record actually gets
The docs case claimed the package does not ship the docs; it does (the
package manifest lists "docs" in "files", there is no .npmignore and the
directory is not git-ignored), so the check runs in the packed install and
the comment was the opposite of the fact.
The service lifetime also promised that Start replaces a leftover, but a
healthy one is only observed: Start reports it as already running and
replaces nothing. The wording now says so, and a case pins it.
* fix(dsh): write the default backend when the selection is cleared
The backend selection is the one managed key with a default. Clearing it
wrote an empty value, and an empty value is not the default: ReMe applies
"${LLM_BACKEND:-openai}" only when the variable is absent, so the service
started with no backend at all and refused to run - while the plugin's own
probe resolved the same empty value to openai and reported a working
configuration.
The cleared selection now writes the default out, and the probe reports an
explicitly empty backend as an incomplete configuration instead of testing a
configuration the service cannot use. A file without the key keeps the
default, and an unknown backend name stays probed tolerantly: the list of
backends here is a snapshot, and ReMe may know more.
* fix(dsh): keep the recovery for an unverified service record
A recorded process that holds the port but whose identity cannot be read
left the tab with no action at all: no Stop (the process is not ours to
signal), no Start (a conflict disables it) and no Forget (nothing had
refused yet, so no record was ever named).
The record now travels with the status, so the card can offer "Forget this
record", and a start names the same record as an unverified one. The process
is still never signalled: an unreadable identity is no proof. A conflict
caused by an unrelated process stays a plain conflict, with no record to
name.
* docs(dsh): describe the cleared backend and the unverified record
The service lifetime now says what a conflict with an unreadable recorded
process offers, and the environment section says what clearing the backend
selection writes and what the probe reports for an explicitly empty one.
* refactor(dsh): decide the recorded service in one place
The manager read the service record and decided its ownership in three
places, and the "launchable" wrapper only repeated the shared endpoint
predicate.
One inspection now answers it: the record, whether its process is alive, and
what can be proven about it. The start path reads that verdict and acts on
it, so the same-origin replacement, the unverified record and the plain port
conflict cannot drift apart. The private launchable() wrapper is gone - the
shared isLocalEndpoint() says the same thing.
* fix(dsh): keep the saved backends and the probe in step with ReMe
Two ways the plugin could write or read a backend the service cannot use:
The embedding backend was left out of the default rule, because this
repository's own configuration has its embedding components commented out.
That only holds for the version in this repository: ReMe 0.4.0.x - the
oldest the plugin supports - declares as_embedding with
"backend: ${EMBEDDING_BACKEND:-openai}" and instantiates it, so an
explicitly empty value names no backend and the service refuses to start,
exactly like the LLM backend did. EMBEDDING_BACKEND now writes its default
out as well.
A known backend written in the wrong case was folded to the default before
the probe ran, so the probe tested a configuration ReMe's case-sensitive
registry refuses ("Unregistered backend 'OpenAI'"). The probe now reports
the spelling to use and sends no request. A name the plugin has never heard
of is still probed tolerantly: its list is a snapshot, and ReMe may know
more than the plugin does.
* fix(dsh): read the protocol table by its own entries
The LLM protocol table is a plain object literal, so it inherits from
Object.prototype: `LLM_PROTOCOLS["constructor"]` and `["__proto__"]`
answered with the inherited members instead of `undefined`. A backend
named that way was therefore not treated as an unknown name: the probe
built a malformed request from `Object` and failed with a generic
"no result", while the upper-case spellings were reported as known
backends written in the wrong case, naming a spelling ReMe refuses too.
Both readers of the table now consult its own entries only, through one
helper, so "what the plugin knows" has a single answer: such a name is
probed tolerantly like any other unknown name, and a name that really is
a known backend in the wrong case is still refused with the spelling to
use.
* fix(dsh): finish environment lifecycle and readiness safeguards
* fix(dsh): close startup races and validate env updates
---------
Co-authored-by: jinli.yl <jinli.yl@alibaba-inc.com>
2014 lines
60 KiB
JavaScript
2014 lines
60 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import React from "react";
|
|
import { act, create } from "react-test-renderer";
|
|
|
|
import { ReMeEnvironmentTab, envZh } from "../dist/environment/client/tab.js";
|
|
import { fill } from "../dist/environment/client/locales.js";
|
|
|
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
const CONDA = "D:\\ProgramFils\\Miniconda";
|
|
const SUGGESTED = `${CONDA}\\envs\\reme-serve\\python.exe`;
|
|
|
|
function env(name, version, reme) {
|
|
const root = name === "base" ? CONDA : `${CONDA}\\envs\\${name}`;
|
|
return {
|
|
exe: `${root}\\python.exe`,
|
|
version,
|
|
ok: true,
|
|
origin: { kind: "conda", envName: name, root },
|
|
source: "conda env list",
|
|
...(reme ? { reme: { installed: true, version: reme } } : {}),
|
|
};
|
|
}
|
|
|
|
const ENVS = [
|
|
env("base", "3.12.3", "0.4.0.9"),
|
|
env("com_env", "3.12.9"),
|
|
env("copaw", "3.12.0", "0.3.1.8"),
|
|
env("drama", "3.12.13"),
|
|
env("mochi", "3.12.13"),
|
|
env("mochi_test", "3.12.13"),
|
|
env("nl_agent", "3.12.0"),
|
|
env("reme-serve", "3.12.13", "0.4.0.9"),
|
|
];
|
|
|
|
const RESPONSES = {
|
|
"remeEnv/python": {
|
|
platform: "win32",
|
|
scannedAt: new Date().toISOString(),
|
|
envs: ENVS,
|
|
suggested: SUGGESTED,
|
|
condaRoot: CONDA,
|
|
errors: [],
|
|
},
|
|
"remeEnv/checkReme": {
|
|
installed: true,
|
|
version: "0.4.0.9",
|
|
versionOk: true,
|
|
hasCore: true,
|
|
cliPath: `${CONDA}\\envs\\reme-serve\\Scripts\\reme.exe`,
|
|
error: "",
|
|
},
|
|
"remeEnv/installStatus": null,
|
|
"remeEnv/readEnv": {
|
|
workspaceDir: "C:\\Users\\test\\.reme",
|
|
exists: true,
|
|
envPath: "C:\\Users\\test\\.reme\\.env",
|
|
entries: [
|
|
{
|
|
key: "LLM_BACKEND",
|
|
value: "dashscope",
|
|
masked: "dashscope",
|
|
secret: false,
|
|
set: true,
|
|
},
|
|
{
|
|
key: "LLM_MODEL_NAME",
|
|
value: "qwen3.7-plus",
|
|
masked: "qwen3.7-plus",
|
|
secret: false,
|
|
set: true,
|
|
},
|
|
],
|
|
},
|
|
"remeEnv/serviceStatus": {
|
|
phase: "running",
|
|
version: "0.4.0.9",
|
|
managed: false,
|
|
pid: 98820,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
};
|
|
|
|
const t = (key) => envZh[key];
|
|
|
|
function textOf(value) {
|
|
if (Array.isArray(value)) return value.map(textOf).join("");
|
|
return typeof value === "string" ? value : "";
|
|
}
|
|
|
|
function classesOf(node, found = new Map()) {
|
|
if (!node || typeof node === "string") return found;
|
|
if (Array.isArray(node)) {
|
|
node.forEach((child) => classesOf(child, found));
|
|
return found;
|
|
}
|
|
for (const name of String(node.props.className ?? "").split(" ")) {
|
|
if (name) found.set(name, (found.get(name) ?? 0) + 1);
|
|
}
|
|
(node.children ?? []).forEach((child) => classesOf(child, found));
|
|
return found;
|
|
}
|
|
|
|
function texts(node, found = []) {
|
|
if (!node) return found;
|
|
if (typeof node === "string") {
|
|
found.push(node);
|
|
return found;
|
|
}
|
|
if (Array.isArray(node)) {
|
|
node.forEach((child) => texts(child, found));
|
|
return found;
|
|
}
|
|
(node.children ?? []).forEach((child) => texts(child, found));
|
|
return found;
|
|
}
|
|
|
|
async function mount(overrides = {}, options = {}) {
|
|
const calls = { mutate: [], rpc: [] };
|
|
const responses = { ...RESPONSES, ...(options.responses ?? {}) };
|
|
const listeners = new Set();
|
|
// A new object per change, the way the Host-backed form publishes a snapshot.
|
|
let snapshot = {
|
|
status: "ready",
|
|
writable: true,
|
|
revision: 3,
|
|
value: {
|
|
endpoint: "http://127.0.0.1:2333",
|
|
pythonPath: "",
|
|
remeWorkspaceDir: "",
|
|
autoStart: false,
|
|
requestTimeoutMs: 10000,
|
|
backgroundTimeoutMs: 3600000,
|
|
...overrides,
|
|
},
|
|
};
|
|
const scope = {
|
|
subscribe: (listener) => {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
},
|
|
getSnapshot: () => snapshot,
|
|
mutate: async (ops, revision) => {
|
|
calls.mutate.push({ ops, revision });
|
|
return options.mutate ? options.mutate() : true;
|
|
},
|
|
};
|
|
const rpc = {
|
|
call: async (_path, method, payload, signal) => {
|
|
calls.rpc.push({ method, input: payload?.args?.input });
|
|
if (options.pending?.includes(method))
|
|
return new Promise((_resolve, reject) => {
|
|
signal?.addEventListener(
|
|
"abort",
|
|
() => reject(new Error("aborted")),
|
|
{ once: true },
|
|
);
|
|
});
|
|
const value = responses[method];
|
|
return {
|
|
ok: true,
|
|
value:
|
|
typeof value === "function"
|
|
? value(payload?.args?.input, signal)
|
|
: value ?? null,
|
|
};
|
|
},
|
|
};
|
|
|
|
let renderer;
|
|
await act(async () => {
|
|
renderer = create(
|
|
React.createElement(ReMeEnvironmentTab, { scope, rpc, t }),
|
|
);
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
return {
|
|
renderer,
|
|
calls,
|
|
setValue(patch) {
|
|
snapshot = {
|
|
...snapshot,
|
|
value: { ...snapshot.value, ...patch },
|
|
};
|
|
for (const listener of listeners) listener();
|
|
},
|
|
restore: () => {
|
|
// Unmount so the effect cleanup paths (aborts, timers) actually run.
|
|
act(() => {
|
|
renderer.unmount();
|
|
});
|
|
listeners.clear();
|
|
},
|
|
};
|
|
}
|
|
|
|
function buttonByText(renderer, label) {
|
|
const found = renderer.root.findAll(
|
|
(node) => node.type === "button" && textOf(node.props.children) === label,
|
|
);
|
|
assert.ok(found.length > 0, `button not found: ${label}`);
|
|
return found[0];
|
|
}
|
|
|
|
test("renders the status hero and the four setup steps", async (t) => {
|
|
const { renderer, restore } = await mount();
|
|
t.after(restore);
|
|
const json = renderer.toJSON();
|
|
const classes = classesOf(json);
|
|
const copy = texts(json).join(" ");
|
|
|
|
assert.equal(classes.get("reme-env-hero"), 1);
|
|
assert.equal(classes.get("reme-env-card"), 4);
|
|
assert.equal(classes.get("reme-env-picked"), 1);
|
|
assert.equal(classes.get("reme-env-metrics"), 1);
|
|
assert.equal(classes.get("reme-env-autostart"), 1);
|
|
|
|
assert.match(copy, /ReMe 本地运行时/);
|
|
assert.match(copy, /已就绪,记忆保存在本地/);
|
|
assert.match(copy, /http:\/\/127\.0\.0\.1:2333/);
|
|
assert.match(copy, /8 个环境/);
|
|
assert.match(copy, /服务 · ReMe 0\.4\.0\.9/);
|
|
assert.match(copy, /Python 3\.12\.13/);
|
|
assert.match(copy, /reme-ai 0\.4\.0\.9/);
|
|
assert.match(copy, /C:\\Users\\test\\\.reme\\\.env/);
|
|
});
|
|
|
|
test("an interpreter without AgentScope cannot offer Start or report ready", async (t) => {
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/checkReme": {
|
|
...RESPONSES["remeEnv/checkReme"],
|
|
hasCore: false,
|
|
},
|
|
"remeEnv/serviceStatus": {
|
|
...RESPONSES["remeEnv/serviceStatus"],
|
|
phase: "stopped",
|
|
pid: undefined,
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
assert.equal(buttonByText(renderer, envZh.startService).props.disabled, true);
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.coreMissing));
|
|
assert.equal(copy.includes(envZh.heroReady), false);
|
|
});
|
|
|
|
for (const [code, error, expected] of [
|
|
["core-missing", "AgentScope missing", envZh.startErrorCoreMissing],
|
|
["constructor", "Unknown Host refusal", "Unknown Host refusal"],
|
|
]) {
|
|
test(`localizes or safely falls back for the ${code} start refusal`, async (t) => {
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": {
|
|
...RESPONSES["remeEnv/serviceStatus"],
|
|
phase: "stopped",
|
|
pid: undefined,
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: "",
|
|
startedAt: new Date().toISOString(),
|
|
code,
|
|
error,
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () =>
|
|
buttonByText(renderer, envZh.startService).props.onClick(),
|
|
);
|
|
assert.ok(texts(renderer.toJSON()).join(" ").includes(expected));
|
|
});
|
|
}
|
|
|
|
test("an older Host refusal without a record never guesses a Forget target", async (t) => {
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": {
|
|
...RESPONSES["remeEnv/serviceStatus"],
|
|
phase: "stopped",
|
|
pid: undefined,
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: "",
|
|
startedAt: new Date().toISOString(),
|
|
code: "unverified-record",
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () =>
|
|
buttonByText(renderer, envZh.startService).props.onClick(),
|
|
);
|
|
assert.equal(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.forgetRecord),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
calls.rpc.some((call) => call.method === "remeEnv/serviceForget"),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("keeps the interpreter list collapsed until asked, then paginates", async (t) => {
|
|
const { renderer, restore } = await mount();
|
|
t.after(restore);
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), undefined);
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.changeInterpreter).props.onClick();
|
|
});
|
|
const expanded = classesOf(renderer.toJSON());
|
|
assert.equal(expanded.get("reme-env-option"), 6);
|
|
assert.equal(expanded.get("reme-env-search"), 1);
|
|
assert.equal(expanded.get("reme-env-more"), 1);
|
|
|
|
await act(async () => {
|
|
renderer.root
|
|
.findAll(
|
|
(node) =>
|
|
node.type === "button" && textOf(node.props.children).includes("8"),
|
|
)[0]
|
|
.props.onClick();
|
|
});
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), 8);
|
|
});
|
|
|
|
test("marks the suggested interpreter and explains why", async (t) => {
|
|
const { renderer, calls, restore } = await mount();
|
|
t.after(restore);
|
|
const json = renderer.toJSON();
|
|
const recommended = renderer.root.findAll(
|
|
(node) =>
|
|
String(node.props.className ?? "").includes("reme-env-tag brand") &&
|
|
textOf(node.props.children) === envZh.recommended,
|
|
);
|
|
assert.ok(recommended.length >= 1);
|
|
assert.equal(recommended[0].props.title, envZh.recommendWhyReme);
|
|
assert.ok(texts(json).join(" ").includes(SUGGESTED));
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.changeInterpreter).props.onClick();
|
|
});
|
|
const radios = renderer.root.findAll(
|
|
(node) => node.type === "input" && node.props.type === "radio",
|
|
);
|
|
// The current interpreter stays in the group, checked and disabled, so
|
|
// assistive technology can announce the selection.
|
|
assert.equal(radios.filter((node) => node.props.checked === true).length, 1);
|
|
assert.equal(
|
|
radios.find((node) => node.props.checked === true).props.disabled,
|
|
true,
|
|
);
|
|
const target = radios.find((node) => node.props.disabled === false);
|
|
assert.ok(target);
|
|
await act(async () => {
|
|
target.props.onChange();
|
|
});
|
|
assert.deepEqual(calls.mutate.at(-1)?.ops, [
|
|
{ op: "set", path: ["pythonPath"], value: ENVS[0].exe },
|
|
]);
|
|
});
|
|
|
|
test("sends the chosen package mirror with the install request", async (t) => {
|
|
const { renderer, calls, restore } = await mount();
|
|
t.after(restore);
|
|
|
|
const select = renderer.root.findAll((node) => node.type === "select")[0];
|
|
await act(async () => {
|
|
select.props.onChange({
|
|
target: { value: "https://pypi.tuna.tsinghua.edu.cn/simple" },
|
|
});
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.reinstall).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
|
|
const install = calls.rpc.filter((call) => call.method === "remeEnv/install");
|
|
assert.ok(install.length > 0, "the install request must be sent");
|
|
assert.deepEqual(install.at(-1).input, {
|
|
pythonPath: SUGGESTED,
|
|
upgrade: false,
|
|
indexUrl: "https://pypi.tuna.tsinghua.edu.cn/simple",
|
|
forceReinstall: true,
|
|
});
|
|
});
|
|
|
|
test("drops .env drafts when the workspace changes", async (t) => {
|
|
const { renderer, calls, setValue, restore } = await mount();
|
|
t.after(restore);
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
const apiKey = () =>
|
|
renderer.root.findAll(
|
|
(node) => node.type === "input" && node.props.type === "password",
|
|
)[0];
|
|
await act(async () => {
|
|
apiKey().props.onChange({
|
|
target: { value: "sk-typed-for-first-workspace" },
|
|
});
|
|
});
|
|
assert.equal(apiKey().props.value, "sk-typed-for-first-workspace");
|
|
|
|
// The tab remounts the section for the new workspace, which disposes the
|
|
// previous section's state — including the draft typed for it.
|
|
await act(async () => {
|
|
setValue({ remeWorkspaceDir: "/tmp/second-workspace" });
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
// The draft belonged to the first workspace and is gone with it, so a save
|
|
// cannot carry a key typed for one workspace into another.
|
|
assert.equal(apiKey().props.value, "");
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.saveEnv).props.onClick();
|
|
});
|
|
const write = calls.rpc
|
|
.filter((call) => call.method === "remeEnv/writeEnv")
|
|
.at(-1);
|
|
assert.ok(write);
|
|
assert.equal(write.input.workspaceDir, "/tmp/second-workspace");
|
|
assert.deepEqual(write.input.values, {});
|
|
});
|
|
|
|
test("probes the service from the Host, never from the browser", async (t) => {
|
|
const original = globalThis.fetch;
|
|
let fetched = 0;
|
|
globalThis.fetch = async () => {
|
|
fetched += 1;
|
|
throw new Error("the tab must not fetch the service URL itself");
|
|
};
|
|
t.after(() => {
|
|
globalThis.fetch = original;
|
|
});
|
|
const { renderer, calls, restore } = await mount();
|
|
t.after(restore);
|
|
assert.equal(fetched, 0);
|
|
assert.match(
|
|
texts(renderer.toJSON()).join(" "),
|
|
/服务 · ReMe 0\.4\.0\.9/,
|
|
"the hero reports the version the Host service probe returned",
|
|
);
|
|
assert.ok(
|
|
calls.rpc.some((call) => call.method === "remeEnv/serviceStatus"),
|
|
"the hero reads its connection from the Host service probe",
|
|
);
|
|
assert.equal(
|
|
calls.rpc.some((call) => call.method === "remeEnv/health"),
|
|
false,
|
|
"a local endpoint is covered by the service probe already",
|
|
);
|
|
});
|
|
|
|
test("a remote endpoint never runs the local setup steps", async (t) => {
|
|
const { calls, restore } = await mount(
|
|
{ endpoint: "http://10.0.0.5:2333" },
|
|
{
|
|
responses: {
|
|
"remeEnv/health": {
|
|
endpoint: "http://10.0.0.5:2333",
|
|
ok: false,
|
|
version: "",
|
|
error: "unreachable",
|
|
checkedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
const methods = calls.rpc.map((call) => call.method);
|
|
assert.ok(
|
|
methods.includes("remeEnv/health"),
|
|
"a remote endpoint is only health-checked",
|
|
);
|
|
for (const local of [
|
|
"remeEnv/python",
|
|
"remeEnv/checkReme",
|
|
"remeEnv/readEnv",
|
|
"remeEnv/serviceStatus",
|
|
])
|
|
assert.equal(methods.includes(local), false, `${local} must not run`);
|
|
});
|
|
|
|
test("a prefixed loopback endpoint is probed, never launched locally", async (t) => {
|
|
const endpoint = "http://127.0.0.1:2333/reme";
|
|
const { calls, restore } = await mount(
|
|
{ endpoint },
|
|
{
|
|
responses: {
|
|
"remeEnv/health": {
|
|
endpoint,
|
|
ok: true,
|
|
version: "0.4.0.9",
|
|
error: "",
|
|
checkedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
const methods = calls.rpc.map((call) => call.method);
|
|
// A gateway mounted under a path prefix keeps its connection probe...
|
|
assert.ok(
|
|
methods.includes("remeEnv/health"),
|
|
"the prefixed endpoint is still health-checked",
|
|
);
|
|
// ...but the plugin cannot launch a service at that prefix: the launch only
|
|
// configures host and port, so the startup health check would never pass.
|
|
for (const local of [
|
|
"remeEnv/python",
|
|
"remeEnv/checkReme",
|
|
"remeEnv/readEnv",
|
|
"remeEnv/serviceStatus",
|
|
])
|
|
assert.equal(methods.includes(local), false, `${local} must not run`);
|
|
});
|
|
|
|
test("shows why Stop left the service alone", async (t) => {
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 98820,
|
|
version: "0.4.0.9",
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
"remeEnv/serviceStop": {
|
|
stopped: false,
|
|
reason: "The recorded process identity could not be verified",
|
|
code: "unverified",
|
|
record: { endpoint: "http://127.0.0.1:2333", pid: 98820 },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
});
|
|
// The Host code is localized in the UI instead of leaking its English text.
|
|
assert.ok(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.stopUnknownIdentity),
|
|
);
|
|
// Stop can never succeed for this record, so the record-only way out is
|
|
// offered next to the explanation.
|
|
assert.ok(buttonByText(renderer, envZh.forgetRecord));
|
|
});
|
|
|
|
test("a process that survived the force-kill still offers forgetting the record", async (t) => {
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 98820,
|
|
version: "0.4.0.9",
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
"remeEnv/serviceStop": {
|
|
stopped: false,
|
|
reason: "The service did not exit after the force-kill",
|
|
code: "not-exited",
|
|
record: { endpoint: "http://127.0.0.1:2333", pid: 98820 },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.stopNotExited));
|
|
// Start would refuse with `previous-not-stopped`, so the record must be
|
|
// forgettable instead of leaving no exit at all.
|
|
assert.ok(buttonByText(renderer, envZh.forgetRecord));
|
|
});
|
|
|
|
test("surfaces a rejected settings write", async (t) => {
|
|
const { renderer, restore } = await mount({}, { mutate: async () => false });
|
|
t.after(restore);
|
|
const checkbox = renderer.root.findAll(
|
|
(node) => node.type === "input" && node.props.type === "checkbox",
|
|
)[0];
|
|
assert.ok(checkbox);
|
|
await act(async () => {
|
|
checkbox.props.onChange({ target: { checked: true } });
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
});
|
|
assert.match(texts(renderer.toJSON()).join(" "), /设置未保存/);
|
|
});
|
|
|
|
test("an aborted LLM test releases its button", async (t) => {
|
|
const { renderer, setValue, restore } = await mount(
|
|
{},
|
|
{ pending: ["remeEnv/testLlm"] },
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.testLlmButton).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
});
|
|
assert.ok(texts(renderer.toJSON()).join(" ").includes(envZh.testingLlm));
|
|
|
|
// Switching workspaces disposes the running probe with its section instead
|
|
// of leaving the new workspace's button on "Testing…".
|
|
await act(async () => {
|
|
setValue({ remeWorkspaceDir: "/tmp/second-workspace" });
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.equal(copy.includes(envZh.testingLlm), false);
|
|
assert.ok(copy.includes(envZh.testLlmButton), "the button is usable again");
|
|
});
|
|
|
|
test("a start that died before listening reports immediately", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": stopped,
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_200));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.startFailedStopped));
|
|
// The message is already a complete sentence; prefixing it would read
|
|
// "Service operation failed: The service exited…".
|
|
assert.equal(copy.includes(`${envZh.serviceError}:`), false);
|
|
// Ready to retry without waiting out the 120 s deadline.
|
|
assert.ok(buttonByText(renderer, envZh.startService));
|
|
});
|
|
|
|
test("a start that lands on a foreign conflict shows the conflict state", async (t) => {
|
|
let calls = 0;
|
|
const states = [
|
|
{
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
{
|
|
phase: "conflict",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
];
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": () =>
|
|
states[Math.min(calls++, states.length - 1)],
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: states[0].logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_200));
|
|
});
|
|
assert.ok(texts(renderer.toJSON()).join(" ").includes(envZh.conflictNote));
|
|
});
|
|
|
|
test("Reinstall forces a reinstall while install and upgrade use the right flags", async () => {
|
|
const upgrade = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/checkReme": {
|
|
installed: true,
|
|
version: "0.3.1.8",
|
|
versionOk: false,
|
|
hasCore: false,
|
|
cliPath: "",
|
|
error: "",
|
|
},
|
|
},
|
|
},
|
|
);
|
|
await act(async () => {
|
|
buttonByText(upgrade.renderer, envZh.upgradeButton).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(upgrade.renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
const upgradeCall = upgrade.calls.rpc
|
|
.filter((call) => call.method === "remeEnv/install")
|
|
.at(-1);
|
|
assert.deepEqual(upgradeCall.input, {
|
|
pythonPath: SUGGESTED,
|
|
upgrade: true,
|
|
});
|
|
upgrade.restore();
|
|
|
|
const fresh = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/checkReme": {
|
|
installed: false,
|
|
version: "",
|
|
versionOk: false,
|
|
hasCore: false,
|
|
cliPath: "",
|
|
error: "",
|
|
},
|
|
},
|
|
},
|
|
);
|
|
await act(async () => {
|
|
buttonByText(fresh.renderer, envZh.installButton).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(fresh.renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
const freshCall = fresh.calls.rpc
|
|
.filter((call) => call.method === "remeEnv/install")
|
|
.at(-1);
|
|
assert.deepEqual(freshCall.input, {
|
|
pythonPath: SUGGESTED,
|
|
upgrade: false,
|
|
});
|
|
fresh.restore();
|
|
|
|
const reinstall = await mount();
|
|
await act(async () => {
|
|
buttonByText(reinstall.renderer, envZh.reinstall).props.onClick();
|
|
});
|
|
// The confirmation copy follows the Reinstall CTA, not the first-install one.
|
|
assert.ok(
|
|
texts(reinstall.renderer.toJSON())
|
|
.join(" ")
|
|
.includes(envZh.reinstallConfirm.split("{path}")[0]),
|
|
);
|
|
await act(async () => {
|
|
buttonByText(reinstall.renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
const reinstallCall = reinstall.calls.rpc
|
|
.filter((call) => call.method === "remeEnv/install")
|
|
.at(-1);
|
|
assert.deepEqual(reinstallCall.input, {
|
|
pythonPath: SUGGESTED,
|
|
upgrade: false,
|
|
forceReinstall: true,
|
|
});
|
|
reinstall.restore();
|
|
});
|
|
|
|
test("localizes a coded start error instead of showing Host English", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": stopped,
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "Another process is already listening on this endpoint",
|
|
code: "conflict",
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.startErrorConflict));
|
|
assert.equal(copy.includes("Another process is already listening"), false);
|
|
});
|
|
|
|
test("switching the endpoint aborts the previous start poll", async (t) => {
|
|
const OLD = "http://127.0.0.1:2333";
|
|
const NEW = "http://127.0.0.1:2444";
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: OLD,
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const newRunning = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 1111,
|
|
endpoint: NEW,
|
|
version: "9.9.9",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const oldRunning = {
|
|
...newRunning,
|
|
pid: 5000,
|
|
endpoint: OLD,
|
|
version: "0.4.0.9",
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, setValue, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": (input) => {
|
|
if (input?.endpoint === NEW) return newRunning;
|
|
statusCalls += 1;
|
|
return statusCalls === 1 ? stopped : oldRunning;
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
// Switch before the poll's 1 s tick: it must not paint the old endpoint's
|
|
// running data under the new URL.
|
|
await act(async () => {
|
|
setValue({ endpoint: NEW });
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_200));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("PID 1111"), "the new endpoint's pid is shown");
|
|
assert.equal(copy.includes("PID 5000"), false);
|
|
});
|
|
|
|
test("a live record that never listened offers Stop instead of 'Starting'", async (t) => {
|
|
// The Host reports a recorded launch that is still alive but not listening
|
|
// as `stopped` + pid. Mapping that to `starting` on every read used to lock
|
|
// the card: Start disabled, no Stop, and Recheck repeated the same answer.
|
|
const stale = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
pid: 6000,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{ responses: { "remeEnv/serviceStatus": stale } },
|
|
);
|
|
t.after(restore);
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.equal(copy.includes(envZh.serviceBadgeStarting), false);
|
|
assert.ok(copy.includes(envZh.serviceBadgeStale));
|
|
assert.ok(copy.includes(envZh.staleNote));
|
|
// Stop is the way out for a provably owned leftover...
|
|
const stop = buttonByText(renderer, envZh.stopService);
|
|
assert.equal(stop.props.disabled, false, "the recorded pid can be stopped");
|
|
// ...and Start must stay available too: the pid may have been recycled by a
|
|
// foreign process, where Stop refuses and only a restart self-heals.
|
|
const start = buttonByText(renderer, envZh.startService);
|
|
assert.equal(start.props.disabled, false, "Start can replace the record");
|
|
});
|
|
|
|
test("Start replaces a stale record that belongs to a foreign pid", async (t) => {
|
|
// The pid is alive but no longer our service, so Stop answers `foreign` and
|
|
// keeps the record. Start must still be offered: the Host discards a foreign
|
|
// record and launches a fresh service.
|
|
const stale = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
pid: 6000,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const running = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 7000,
|
|
version: "0.4.0.9",
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: stale.logPath,
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": () => {
|
|
statusCalls += 1;
|
|
return statusCalls === 1 ? stale : running;
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: stale.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_200));
|
|
});
|
|
assert.ok(
|
|
calls.rpc.some((call) => call.method === "remeEnv/serviceStart"),
|
|
"the restart really reached the Host",
|
|
);
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("ReMe 0.4.0.9"));
|
|
assert.ok(copy.includes("PID 7000"));
|
|
});
|
|
|
|
test("an owned conflict during a start keeps polling until healthy", async (t) => {
|
|
const stop = (pid) => ({
|
|
phase: "stopped",
|
|
managed: false,
|
|
...(pid === undefined ? {} : { pid }),
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
});
|
|
const conflict = {
|
|
phase: "conflict",
|
|
managed: true,
|
|
pid: 6000,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const running = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 6000,
|
|
version: "0.4.0.9",
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": () => {
|
|
statusCalls += 1;
|
|
if (statusCalls === 1) return stop();
|
|
if (statusCalls === 2) return conflict;
|
|
return running;
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: running.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_200));
|
|
});
|
|
// One owned conflict is our own launch booting; it must not become a Stop
|
|
// offer that would kill a service which is about to answer.
|
|
assert.ok(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.serviceBadgeStarting),
|
|
);
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 1_100));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("ReMe 0.4.0.9"));
|
|
assert.equal(copy.includes(envZh.conflictManagedNote), false);
|
|
});
|
|
|
|
test("a Host conflict refusal shows the conflict card, not an error", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const conflict = {
|
|
phase: "conflict",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: stopped.logPath,
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": () => {
|
|
statusCalls += 1;
|
|
return statusCalls === 1 ? stopped : conflict;
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "Another process is already listening on this endpoint",
|
|
code: "conflict",
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.conflictNote));
|
|
assert.equal(copy.includes(envZh.startErrorConflict), false);
|
|
});
|
|
|
|
test("a slow status answer does not overwrite a finished start", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const running = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 7000,
|
|
version: "0.4.0.9",
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: stopped.logPath,
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": () => {
|
|
statusCalls += 1;
|
|
if (statusCalls === 1) return stopped;
|
|
// The manual Recheck answers late, after the start poll has settled.
|
|
if (statusCalls === 2)
|
|
return new Promise((resolve) =>
|
|
setTimeout(() => resolve(stopped), 1_500),
|
|
);
|
|
return running;
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: true,
|
|
alreadyRunning: false,
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
const rechecks = renderer.root.findAll(
|
|
(node) =>
|
|
node.type === "button" && textOf(node.props.children) === envZh.recheck,
|
|
);
|
|
await act(async () => {
|
|
rechecks.at(-1).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 2_300));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("ReMe 0.4.0.9"));
|
|
assert.equal(copy.includes(envZh.serviceBadgeStopped), false);
|
|
});
|
|
|
|
test("a Stop result for the previous endpoint is dropped", async (t) => {
|
|
const OLD = "http://127.0.0.1:2333";
|
|
const NEW = "http://127.0.0.1:2444";
|
|
const oldRunning = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 5000,
|
|
version: "0.4.0.9",
|
|
endpoint: OLD,
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const newRunning = {
|
|
...oldRunning,
|
|
pid: 1111,
|
|
version: "9.9.9",
|
|
endpoint: NEW,
|
|
};
|
|
let release;
|
|
const stopResult = new Promise((resolve) => {
|
|
release = resolve;
|
|
});
|
|
const { renderer, setValue, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": (input) =>
|
|
input?.endpoint === NEW ? newRunning : oldRunning,
|
|
"remeEnv/serviceStop": () => stopResult,
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.stopService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
setValue({ endpoint: NEW });
|
|
});
|
|
await act(async () => {
|
|
release({
|
|
stopped: false,
|
|
reason: "could not be verified",
|
|
code: "unverified",
|
|
});
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.equal(copy.includes(envZh.stopUnknownIdentity), false);
|
|
const stops = renderer.root.findAll(
|
|
(node) =>
|
|
node.type === "button" &&
|
|
textOf(node.props.children) === envZh.stopService,
|
|
);
|
|
assert.ok(stops.length > 0);
|
|
assert.equal(stops[0].props.disabled, false);
|
|
});
|
|
|
|
test("localizes a Host health failure code", async (t) => {
|
|
const { renderer, restore } = await mount(
|
|
{ endpoint: "http://10.0.0.5:2333" },
|
|
{
|
|
responses: {
|
|
"remeEnv/health": {
|
|
endpoint: "http://10.0.0.5:2333",
|
|
ok: false,
|
|
version: "",
|
|
error: "The endpoint did not answer with a ReMe health report",
|
|
code: "not-reme",
|
|
checkedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.healthErrorNotReme));
|
|
assert.equal(
|
|
copy.includes("did not answer with a ReMe health report"),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("a Python refresh keeps the previous interpreter list on screen", async (t) => {
|
|
let pythonCalls = 0;
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/python": () => {
|
|
pythonCalls += 1;
|
|
// The refresh never answers; the previous detection must stay.
|
|
return pythonCalls === 1
|
|
? RESPONSES["remeEnv/python"]
|
|
: new Promise(() => {});
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.changeInterpreter).props.onClick();
|
|
});
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), 6);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.refresh).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.equal(copy.includes(envZh.emptyTitle), false);
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), 6);
|
|
});
|
|
|
|
test("a failed Python refresh keeps the working list without the empty state", async (t) => {
|
|
let pythonCalls = 0;
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/python": () => {
|
|
pythonCalls += 1;
|
|
if (pythonCalls === 1) return RESPONSES["remeEnv/python"];
|
|
throw new Error("probe exploded");
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.changeInterpreter).props.onClick();
|
|
});
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), 6);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.refresh).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.detectFailed));
|
|
// A failed probe that still has the previous result must not claim that no
|
|
// Python exists, nor offer Miniconda next to a valid interpreter list.
|
|
assert.equal(copy.includes(envZh.emptyTitle), false);
|
|
assert.equal(classesOf(renderer.toJSON()).get("reme-env-option"), 6);
|
|
});
|
|
|
|
test("the conflict fallback of a start does not paint an aborted request", async (t) => {
|
|
const OLD = "http://127.0.0.1:2333";
|
|
const NEW = "http://127.0.0.1:2444";
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: OLD,
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const newRunning = {
|
|
phase: "running",
|
|
managed: true,
|
|
pid: 1111,
|
|
version: "9.9.9",
|
|
endpoint: NEW,
|
|
logPath: stopped.logPath,
|
|
};
|
|
let statusCalls = 0;
|
|
const { renderer, setValue, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": (input, signal) => {
|
|
if (input?.endpoint === NEW) return newRunning;
|
|
statusCalls += 1;
|
|
if (statusCalls === 1) return stopped;
|
|
// The R3 re-query hangs until the endpoint switch aborts it.
|
|
return new Promise((_resolve, reject) => {
|
|
signal?.addEventListener(
|
|
"abort",
|
|
() => reject(new Error("aborted")),
|
|
{ once: true },
|
|
);
|
|
});
|
|
},
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "Another process is already listening on this endpoint",
|
|
code: "conflict",
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
});
|
|
await act(async () => {
|
|
setValue({ endpoint: NEW });
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("ReMe 9.9.9"), "the new endpoint state is shown");
|
|
// The old endpoint's conflict error must not land on the new card.
|
|
assert.equal(copy.includes(envZh.startErrorConflict), false);
|
|
});
|
|
|
|
test("an unverified record reports the pid it refused to touch", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": stopped,
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "The recorded service identity could not be verified",
|
|
code: "unverified-record",
|
|
record: { endpoint: "http://127.0.0.1:2333", pid: 6000 },
|
|
pid: 6000,
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
"remeEnv/serviceForget": { forgotten: true, pid: 6000 },
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes("PID 6000"));
|
|
assert.equal(copy.includes("The recorded service identity"), false);
|
|
|
|
// Both Start and Stop are guaranteed to fail here, so the record-only way
|
|
// out must be offered instead of leaving the card with no working action.
|
|
assert.ok(copy.includes(envZh.forgetHint));
|
|
assert.ok(buttonByText(renderer, envZh.forgetRecord));
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
assert.ok(
|
|
texts(renderer.toJSON())
|
|
.join(" ")
|
|
.includes(
|
|
fill(envZh.forgetConfirmRecord, { endpoint: "http://127.0.0.1:2333" }),
|
|
),
|
|
"the confirmation names the record it forgets",
|
|
);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
assert.ok(
|
|
calls.rpc.some((call) => call.method === "remeEnv/serviceForget"),
|
|
"forgetting reaches the Host",
|
|
);
|
|
const after = texts(renderer.toJSON()).join(" ");
|
|
assert.equal(after.includes(envZh.forgetHint), false);
|
|
assert.equal(after.includes(envZh.forgetRecord), false);
|
|
});
|
|
|
|
test("a successful install refreshes the dependency check", async (t) => {
|
|
// The card used to keep reporting "not installed" after a successful
|
|
// install, so Start stayed disabled until the user pressed Check by hand.
|
|
let checkCalls = 0;
|
|
const job = {
|
|
id: "install-1",
|
|
phase: "running",
|
|
pythonPath: SUGGESTED,
|
|
command: "pip install reme-ai[core]",
|
|
startedAt: new Date().toISOString(),
|
|
logPath: "C:\\Users\\test\\.reme\\install-1.log",
|
|
logTail: "",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/checkReme": () => {
|
|
checkCalls += 1;
|
|
return checkCalls === 1
|
|
? {
|
|
installed: false,
|
|
version: "",
|
|
versionOk: false,
|
|
hasCore: false,
|
|
cliPath: "",
|
|
error: "",
|
|
}
|
|
: {
|
|
installed: true,
|
|
version: "0.4.0.9",
|
|
versionOk: true,
|
|
hasCore: true,
|
|
cliPath: "",
|
|
error: "",
|
|
};
|
|
},
|
|
"remeEnv/install": () => job,
|
|
"remeEnv/installStatus": (input) =>
|
|
input?.jobId
|
|
? {
|
|
...job,
|
|
phase: "succeeded",
|
|
finishedAt: new Date().toISOString(),
|
|
}
|
|
: null,
|
|
"remeEnv/serviceStatus": {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
assert.ok(texts(renderer.toJSON()).join(" ").includes(envZh.notInstalled));
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.installButton).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
});
|
|
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(
|
|
copy.includes(envZh.installSucceeded),
|
|
"the install reports success",
|
|
);
|
|
// The dependency check ran again for this interpreter.
|
|
const checks = calls.rpc.filter(
|
|
(call) => call.method === "remeEnv/checkReme",
|
|
);
|
|
assert.ok(checks.length >= 2, "the check is rerun after the install");
|
|
assert.ok(
|
|
copy.includes("reme-ai 0.4.0.9"),
|
|
"the card shows the freshly installed version",
|
|
);
|
|
// Start is usable again now that the dependency is there.
|
|
assert.equal(
|
|
buttonByText(renderer, envZh.startService).props.disabled,
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("an install answer for another interpreter is dropped", async (t) => {
|
|
let release;
|
|
const pending = new Promise((resolve) => {
|
|
release = resolve;
|
|
});
|
|
const job = {
|
|
id: "install-9",
|
|
phase: "running",
|
|
pythonPath: SUGGESTED,
|
|
command: "pip install reme-ai[core]",
|
|
startedAt: new Date().toISOString(),
|
|
logPath: "C:\\Users\\test\\.reme\\install-9.log",
|
|
logTail: "",
|
|
};
|
|
const { renderer, setValue, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/install": () => pending,
|
|
// The Host keeps reporting the job as running, so a job that leaks
|
|
// into the new interpreter stays visible instead of being wiped by the
|
|
// next poll.
|
|
"remeEnv/installStatus": (input) => (input?.jobId ? job : null),
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.reinstall).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.confirmInstall).props.onClick();
|
|
});
|
|
// The interpreter changes while the install request is still in flight.
|
|
await act(async () => {
|
|
setValue({ pythonPath: ENVS[0].exe });
|
|
});
|
|
await act(async () => {
|
|
release(job);
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
// The job belongs to the previous interpreter: it must not be shown here,
|
|
// and it must not be cancellable from here either.
|
|
assert.equal(copy.includes(envZh.installing), false);
|
|
assert.equal(copy.includes(envZh.cancelInstall), false);
|
|
});
|
|
|
|
test("a running job is restored for the selected interpreter", async (t) => {
|
|
const job = {
|
|
id: "install-7",
|
|
phase: "running",
|
|
pythonPath: SUGGESTED,
|
|
command: "pip install reme-ai[core]",
|
|
startedAt: new Date().toISOString(),
|
|
logPath: "C:\\Users\\test\\.reme\\install-7.log",
|
|
logTail: "Collecting reme-ai",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/installStatus": (input) =>
|
|
input?.jobId || input?.pythonPath ? job : null,
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
assert.ok(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.installing),
|
|
"the running job is shown again",
|
|
);
|
|
// The Host is asked for the job of this interpreter, not for the newest job
|
|
// overall: another interpreter may be installing at the same time.
|
|
const lookups = calls.rpc.filter(
|
|
(call) => call.method === "remeEnv/installStatus",
|
|
);
|
|
assert.ok(lookups.length > 0);
|
|
assert.equal(lookups[0].input.pythonPath, SUGGESTED);
|
|
});
|
|
|
|
test("the LLM test waits for the backend that is saved on disk", async (t) => {
|
|
const { renderer, restore } = await mount();
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
// The saved backend is the one the probe would use.
|
|
assert.equal(
|
|
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
|
false,
|
|
);
|
|
|
|
// Picking another backend in the form does not change the file on disk, so
|
|
// the test would probe the old one.
|
|
const backend = renderer.root
|
|
.findAll((node) => node.type === "select")
|
|
.find((node) => node.props.value === "dashscope");
|
|
assert.ok(backend, "the LLM backend select");
|
|
await act(async () => {
|
|
backend.props.onChange({ target: { value: "anthropic" } });
|
|
});
|
|
assert.ok(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.testLlmSaveFirst),
|
|
"the button explains that the .env has to be saved first",
|
|
);
|
|
assert.equal(
|
|
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("the LLM test waits for every unsaved probe setting", async (t) => {
|
|
// The probe reads the whole .env from disk, so a changed model or key is
|
|
// just as untested as a changed backend.
|
|
const { renderer, restore } = await mount();
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
const model = renderer.root.findAll(
|
|
(node) => node.type === "input" && node.props.value === "qwen3.7-plus",
|
|
);
|
|
assert.ok(model.length > 0, "the model field");
|
|
await act(async () => {
|
|
model[0].props.onChange({ target: { value: "another-model" } });
|
|
});
|
|
assert.equal(
|
|
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
|
true,
|
|
"an unsaved model is not the model the probe would use",
|
|
);
|
|
|
|
// A typed key is not on disk either.
|
|
const fresh = await mount();
|
|
try {
|
|
await act(async () => {
|
|
buttonByText(fresh.renderer, envZh.expand).props.onClick();
|
|
});
|
|
const key = fresh.renderer.root.findAll(
|
|
(node) => node.type === "input" && node.props.type === "password",
|
|
)[0];
|
|
await act(async () => {
|
|
key.props.onChange({ target: { value: "sk-typed" } });
|
|
});
|
|
assert.equal(
|
|
buttonByText(fresh.renderer, envZh.testLlmButton).props.disabled,
|
|
true,
|
|
"an unsaved key is not the key the probe would use",
|
|
);
|
|
} finally {
|
|
fresh.restore();
|
|
}
|
|
});
|
|
|
|
test("picking the default backend is not treated as a change", async (t) => {
|
|
// The .env names no backend, so ReMe and the probe both use the default;
|
|
// choosing it in the form changes nothing.
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/readEnv": {
|
|
workspaceDir: "C:\\Users\\test\\.reme",
|
|
exists: true,
|
|
envPath: "C:\\Users\\test\\.reme\\.env",
|
|
entries: [
|
|
{
|
|
key: "LLM_MODEL_NAME",
|
|
value: "qwen3.7-plus",
|
|
masked: "qwen3.7-plus",
|
|
secret: false,
|
|
set: true,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.expand).props.onClick();
|
|
});
|
|
const backend = renderer.root
|
|
.findAll((node) => node.type === "select")
|
|
// The LLM backend is the only select that offers the native providers;
|
|
// the mirror and the embedding backend have their own options.
|
|
.find((node) =>
|
|
node.props.children
|
|
.flat(Infinity)
|
|
.some((option) => option?.props?.value === "anthropic"),
|
|
);
|
|
assert.ok(backend, "the LLM backend select");
|
|
await act(async () => {
|
|
backend.props.onChange({ target: { value: "openai" } });
|
|
});
|
|
assert.equal(
|
|
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
|
false,
|
|
"the default backend is what the probe already uses",
|
|
);
|
|
});
|
|
|
|
test("a restored job is matched by the interpreter's own path semantics", async (t) => {
|
|
// The Host reports the interpreter with its own spelling; a Windows path
|
|
// folds case and separators, so the job is still the one on screen.
|
|
const job = {
|
|
id: "install-8",
|
|
phase: "running",
|
|
pythonPath: SUGGESTED.replaceAll("\\", "/").toLowerCase(),
|
|
command: "pip install reme-ai[core]",
|
|
startedAt: new Date().toISOString(),
|
|
logPath: "C:\\Users\\test\\.reme\\install-8.log",
|
|
logTail: "",
|
|
};
|
|
const { renderer, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/installStatus": (input) =>
|
|
input?.jobId || input?.pythonPath ? job : null,
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
assert.ok(
|
|
texts(renderer.toJSON()).join(" ").includes(envZh.installing),
|
|
"the running job is shown again",
|
|
);
|
|
});
|
|
|
|
test("Forget targets the record the Host named, not the endpoint on screen", async (t) => {
|
|
const CARD = "http://127.0.0.1:2444";
|
|
const RECORD = "http://127.0.0.1:2333";
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: CARD,
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{ endpoint: CARD },
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": stopped,
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "The recorded service could not be verified",
|
|
code: "unverified-record",
|
|
pid: 6000,
|
|
record: { endpoint: RECORD, pid: 6000 },
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
"remeEnv/serviceForget": { forgotten: true, pid: 6000 },
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
// A status read only covers the endpoint on screen, so it must not drop the
|
|
// record that belongs to the other endpoint. The service card owns the last
|
|
// "Check" button; the dependency card has one with the same label.
|
|
const rechecks = renderer.root.findAll(
|
|
(node) =>
|
|
node.type === "button" && textOf(node.props.children) === envZh.recheck,
|
|
);
|
|
await act(async () => {
|
|
rechecks.at(-1).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
assert.ok(
|
|
buttonByText(renderer, envZh.forgetRecord),
|
|
"the record-only way out survives a status read",
|
|
);
|
|
// The confirmation names the record that blocks the start.
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
const confirming = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(
|
|
confirming.includes(RECORD),
|
|
"the confirmation names the blocked record",
|
|
);
|
|
// It names the process the record describes, so the user sees what they are
|
|
// about to delete.
|
|
assert.ok(confirming.includes("6000"), "the confirmation names the pid");
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
|
|
const forget = calls.rpc.find(
|
|
(call) => call.method === "remeEnv/serviceForget",
|
|
);
|
|
assert.ok(forget, "forgetting reaches the Host");
|
|
assert.equal(
|
|
forget.input.endpoint,
|
|
RECORD,
|
|
"the record's own endpoint is used, not the endpoint on screen",
|
|
);
|
|
assert.equal(forget.input.expectPid, 6000, "the record is pinned by its pid");
|
|
});
|
|
|
|
test("a conflict whose record cannot be verified offers forgetting it", async (t) => {
|
|
// The port is held by a recorded process whose identity cannot be read. The
|
|
// card offers no Stop (the process is not ours to signal) and no Start (a
|
|
// conflict disables it), so the record the Host names with the status is
|
|
// the only way out.
|
|
const CARD = "http://127.0.0.1:2334";
|
|
const conflict = {
|
|
phase: "conflict",
|
|
managed: false,
|
|
endpoint: CARD,
|
|
record: { endpoint: CARD, pid: 6000 },
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{ endpoint: CARD },
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": conflict,
|
|
"remeEnv/serviceForget": { forgotten: true, pid: 6000 },
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
assert.ok(
|
|
buttonByText(renderer, envZh.forgetRecord),
|
|
"the record-only way out is offered without a refused start",
|
|
);
|
|
// The confirmation names the record and the process it describes.
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
const confirming = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(confirming.includes(CARD), "the confirmation names the record");
|
|
assert.ok(confirming.includes("6000"), "the confirmation names the pid");
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
const forget = calls.rpc.find(
|
|
(call) => call.method === "remeEnv/serviceForget",
|
|
);
|
|
assert.ok(forget, "forgetting reaches the Host");
|
|
assert.equal(forget.input.endpoint, CARD);
|
|
assert.equal(forget.input.expectPid, 6000, "the record is pinned by its pid");
|
|
});
|
|
|
|
test("a record that changed is not forgotten on a second click", async (t) => {
|
|
const stopped = {
|
|
phase: "stopped",
|
|
managed: false,
|
|
endpoint: "http://127.0.0.1:2333",
|
|
logPath: "C:\\Users\\test\\.reme\\service.log",
|
|
};
|
|
const { renderer, calls, restore } = await mount(
|
|
{},
|
|
{
|
|
responses: {
|
|
"remeEnv/serviceStatus": stopped,
|
|
"remeEnv/serviceStart": {
|
|
started: false,
|
|
alreadyRunning: false,
|
|
error: "The recorded service identity could not be verified",
|
|
code: "unverified-record",
|
|
pid: 6000,
|
|
record: { endpoint: "http://127.0.0.1:2333", pid: 6000 },
|
|
command: "",
|
|
logPath: stopped.logPath,
|
|
startedAt: new Date().toISOString(),
|
|
},
|
|
// The record was replaced between the offer and the confirmation.
|
|
"remeEnv/serviceForget": {
|
|
forgotten: false,
|
|
reason: "The recorded service changed since it was inspected",
|
|
code: "record-changed",
|
|
pid: 7000,
|
|
record: { endpoint: "http://127.0.0.1:2333", pid: 7000 },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
t.after(restore);
|
|
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.startService).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
buttonByText(renderer, envZh.forgetRecord).props.onClick();
|
|
});
|
|
await act(async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
});
|
|
|
|
const copy = texts(renderer.toJSON()).join(" ");
|
|
assert.ok(copy.includes(envZh.stopRecordChanged), "the refusal is explained");
|
|
// The offer is withdrawn: the record the user confirmed is not the one that
|
|
// is there now, so a second click must not be able to delete it.
|
|
assert.equal(
|
|
renderer.root.findAll(
|
|
(node) =>
|
|
node.type === "button" &&
|
|
textOf(node.props.children) === envZh.forgetRecord,
|
|
).length,
|
|
0,
|
|
);
|
|
assert.equal(
|
|
calls.rpc.filter((call) => call.method === "remeEnv/serviceForget").length,
|
|
1,
|
|
"the withdrawn offer sends no second request",
|
|
);
|
|
});
|