I want a stateful `DeploymentWatcher` class for a single gated treatment deployment.
harbor run -t mimo-v2.6-rl/format-code-task-001321harbor download mimo-v2.6-rl/format-code-task-001321Fix the following issue:
I want a stateful DeploymentWatcher class for a single gated treatment deployment. It should be constructed as new DeploymentWatcher({ kubeClient, logger, deploymentDescriptor, namespace, plugins, pollerIntervalMilliseconds, gatedDeploymentId }), keep per-instance experiment state, and expose getStream(), onAdded(deployment), onModified(deployment), and onDeleted() for the watcher lifecycle.
getStream() should return the Kubernetes watch stream for deploymentDescriptor.treatment.name in the configured namespace by calling the apps/v1 watch deployment client. When onAdded receives a treatment deployment with zero replicas, it should not start an experiment and should clear the treatment experiment annotation. When it receives a treatment deployment with nonzero replicas whose pod spec matches the control deployment pod spec, it should scale treatment to zero and set the gated deployment status annotation to noHarm without polling plugins.
When onAdded receives a nonzero treatment deployment whose pod spec differs from control, it should start an experiment: store the treatment pod spec, set a UTC start time, persist an experiment annotation containing the start time and pod spec hash, call onExperimentStart(startTime) on each plugin, and poll every pollerIntervalMilliseconds. If a valid existing experiment annotation has the same pod spec hash, the watcher should resume with that annotation's start time instead of starting a new clock; invalid or mismatched annotations should be ignored.
Each poll should call every plugin's onExperimentPoll(controlName, treatmentName). If any plugin returns FAIL, the watcher should stop the experiment, clear the experiment annotation, call onExperimentStop() on plugins, scale treatment to zero, and set the gated deployment status annotation to harm. If every plugin returns PASS, it should stop the experiment, update the control deployment pod spec to the stored treatment pod spec, scale treatment to zero, and set the gated deployment status annotation to noHarm. If plugins return only WAIT or a mix of PASS and WAIT, the experiment should keep running; plugin polling errors should be logged and treated as WAIT.
onModified(deployment) should compare the new deployment with the last one seen by the same watcher instance. If replicas or pod spec changed, it should clear any running experiment and then apply the same start/skip behavior as onAdded; if neither changed, it should leave the running experiment alone. onDeleted() should forget the last deployment, stop any active poller, clear experiment state, notify plugins with onExperimentStop(), and clear the experiment annotation.