From 48b47813d5f0f1f8026748372a574987754f5d84 Mon Sep 17 00:00:00 2001 From: Entropy-Enthalpy <55441397+Entropy-Enthalpy@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:57:59 +0800 Subject: [PATCH] refactor: retire migrated native v1 markers --- contracts/compute-limit-context/v1/README.md | 16 ++++--- contracts/compute-restrictions-source.json | 4 +- contracts/native-slurm-source.json | 2 +- docs/architecture.md | 3 +- docs/roadmap.md | 15 ++++--- docs/runtime-design.md | 7 ++- docs/site-local-read-plane.md | 6 ++- site/slurm/job_submit.lua | 13 ++---- src/sai_compute_restrictions.py | 47 ++++++++------------ tests/test_compute_restrictions.py | 37 ++++++++++++--- tests/test_job_pending_reason.py | 16 +++---- tests/test_job_submit_lua.py | 15 +++---- tests/test_local_jobs.py | 5 +-- 13 files changed, 101 insertions(+), 85 deletions(-) diff --git a/contracts/compute-limit-context/v1/README.md b/contracts/compute-limit-context/v1/README.md index 93fabe3..5a1a255 100644 --- a/contracts/compute-limit-context/v1/README.md +++ b/contracts/compute-limit-context/v1/README.md @@ -3,7 +3,8 @@ This additive job field uses the typed association Comment v2 carrier. The public DTO and native carrier have separate version numbers. The public shape is defined by [schema.json](schema.json). Compatible readers and writers for the applied-record -extension are deployed. Full-cohort metadata migration remains incomplete. +extension are deployed. The accepted source migration is complete. The source +now removes native v1 compatibility; paired activation is tracked separately. `limit_context` describes native member limits and the account limits and policy sources last verified by the site writer. Slurm retains the original scheduling reason. The field identifies @@ -86,8 +87,8 @@ During upgrades, compatible CLI, Read gateway and Core DTO consumers precede Site writers for the optional `applied` payload. The v2 frame, SAI native helper and Lua reader are unchanged. The original policy projector and workers refresh metadata while numeric limits remain unchanged. The SAI helper uses -standard Slurm APIs, preserves the original manual suffix and supports both -carrier versions before v2 writes start. Slurm source, libraries and protocol +standard Slurm APIs and preserves the original manual suffix. Current codecs, +writers and helpers accept only v2, with explicit limit metadata. Slurm source, libraries and protocol remain unmodified. The paired deployment completed with the Site/Read update on 2026-11-10. @@ -96,7 +97,10 @@ limit changes. Authenticated remote reads and foreign-job denial passed; the sampled remote job had no applicable annotation, so positive remote source attribution remains unverified. -Existing v1 records remain in the accepted cohort. Keep v1 readable until the -original worker completes that cohort's migration. Metadata backfill and the -remaining remote annotation check are tracked in the +The accepted metadata migration and a current complete observation of the +published scope found no v1 marker or supported retryable v1 input. Before +adopting the current pair on another site, verify the same precondition there. +Unmarked native comments are preserved. The v2 path without an `applied` +record is a separate contract and remains supported. Paired activation and the +remaining positive remote annotation check are tracked in the [roadmap](../../../docs/roadmap.md). diff --git a/contracts/compute-restrictions-source.json b/contracts/compute-restrictions-source.json index 69fb253..a74076a 100644 --- a/contracts/compute-restrictions-source.json +++ b/contracts/compute-restrictions-source.json @@ -1,6 +1,6 @@ { "repository": "AI4SAI/sai-portal", "path": "sai_compute_restrictions.py", - "revision": "e29e8ca2a66fb543b4e65a5caa69e43f92af9751", - "sha256": "2fff6aa7e48392f1e68dd5dfe626463625f9e34fb727e74286151366be4ec5ab" + "revision": "7243928b6b476a453a1df74ce827e7a5a968264a", + "sha256": "3f067727d73f2dbfe0d7ed7ef31022cdd03fda48ddfc277543b75e7ebd1b9c2c" } diff --git a/contracts/native-slurm-source.json b/contracts/native-slurm-source.json index 26dd790..b706531 100644 --- a/contracts/native-slurm-source.json +++ b/contracts/native-slurm-source.json @@ -1,6 +1,6 @@ { "repository": "AI4SAI/sai-portal", "path": "sai_native_slurm.py", - "revision": "a4702e72cf2acbe5bd4cafb776f3d1561cdae594", + "revision": "7243928b6b476a453a1df74ce827e7a5a968264a", "sha256": "2092765b79a1aab6bdc949e5bc5b8815e60eaacd55c808fa5ed7a8db52a413bb" } diff --git a/docs/architecture.md b/docs/architecture.md index c5db556..4e8c551 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -26,7 +26,8 @@ Its optional `applied` record lets the site writer publish verified parent observations in the existing user association. The shared reader binds that record to the visible job and current user association using one bounded native read with `WOPLimits`. Ordinary users need no parent-association privilege. -Older records keep their existing ancestor-read path during migration. The additive +v2 records without `applied` keep their existing ancestor-read path. The retired +v1 native marker is no longer accepted. The additive [`limit_context` contract](../contracts/compute-limit-context/v1/README.md) preserves each group billing layer and the nearest explicit `MaxSubmitJobs` value. Details distinguish recorded account values from current member values, diff --git a/docs/roadmap.md b/docs/roadmap.md index e9cec9d..bbc7d90 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -48,12 +48,15 @@ not imply production activation or completion of a paired rollout. had no applicable limit annotation and returned empty context. - [x] Complete the main account/member source-only metadata batch through the original projector and workers, with native numeric values unchanged. -- [ ] Finish the remaining organization source records and verify an applicable - limit annotation through an ordinary user's authorized remote read. Retain v1 - compatibility until the accepted cohort is complete. -- [ ] Remove temporary v1 marker compatibility after the original worker's - full accepted association cohort has migrated to v2. An `open` funding marker - stays silent throughout and grants no scheduling permission. +- [x] Complete the remaining organization/member source records. A current + observation of the published scope found no v1 markers or retryable v1 input. +- [ ] Verify an applicable limit annotation through an ordinary user's + authorized remote read. Completed source migration is not repeated for this check. +- [x] Remove v1 marker and three-field input compatibility from the shared + codec, Site writer, native helper and Lua notice reader in source. +- [ ] Deploy that paired compatibility removal. An `open` funding marker stays + silent and grants no scheduling permission. Unmarked native comments and the + separate v2 ancestor-read contract retain their existing meaning. - [x] Implement native account discovery, explicit quota directory selection, retained query scopes and numbered allocation inspection diff --git a/docs/runtime-design.md b/docs/runtime-design.md index 4869ec5..02385d1 100644 --- a/docs/runtime-design.md +++ b/docs/runtime-design.md @@ -618,8 +618,11 @@ An `open` account-state marker emits no account notice and does not imply a job can run. Missing or malformed metadata and failed context reads preserve the native job result, with the existing bounded diagnostic on read failure. The shared module adds no local policy file, Center lookup or pricing calculation. -v1 markers remain readable for the paired migration only; activation, backfill -and removal of that bridge are pending in the [roadmap](roadmap.md). +The shared codec accepts only the v2 marker and requires writers to supply +`limits` explicitly. Unmarked native comments retain their original meaning. +Deployments must complete the original metadata migration and confirm that no +supported retry can send the retired three-field input before adopting this +reader/writer pair. The public DTO remains `compute-limit-context/v1`. Native holds, dependencies and selected account/QOS limits use short labels from the same presenter in local, remote and TUI views. Details retain the native diff --git a/docs/site-local-read-plane.md b/docs/site-local-read-plane.md index d196527..a4dba7a 100644 --- a/docs/site-local-read-plane.md +++ b/docs/site-local-read-plane.md @@ -325,8 +325,10 @@ metadata through standard Slurm association Comments. The diagnostic carrier has no controller HTTP fetch, timer or dynamic policy file. The [roadmap](roadmap.md) tracks applied-record activation and metadata refresh. New readers precede writers because earlier strict decoders reject the added -payload key. The helper and Lua v2 frame stay unchanged. v1 remains readable only until the original worker -has migrated the accepted association cohort. Each site still needs +payload key. The current codec, Site writer, helper and Lua notice reader use +the v2 frame. Adopting this pair requires a completed metadata migration and +confirmation that supported retries contain no retired three-field input. +The separate v2 ancestor-read path remains available. Each site still needs verification of its actual service-UID read permission and native environment. The paired `jobs.allocation/v2` projection reads `gres_detail` from that same diff --git a/site/slurm/job_submit.lua b/site/slurm/job_submit.lua index 083ac69..3dc2c75 100644 --- a/site/slurm/job_submit.lua +++ b/site/slurm/job_submit.lua @@ -37,16 +37,9 @@ local function notify_account_restriction(job_desc, job_ptr) local comment = job_desc.assoc_comment if type(comment) ~= "string" or #comment > 65536 then return end local header = "^%[sai%.account%-state/v2:([%w_.+%-]+):(%d+):([%da-f%-]+):(%d+):([%w_]+)" - local source, assoc_id, owner_ref, revision, code, boundary - if string.sub(comment, 1, #"[sai.account-state/v2:") == "[sai.account-state/v2:" then - local encoded - source, assoc_id, owner_ref, revision, code, encoded, boundary = string.match(comment, - header .. ":([%w_%-]+)%]()") - if not encoded then return end - else - source, assoc_id, owner_ref, revision, code, boundary = string.match(comment, - "^%[sai%.account%-state/v1:([%w_.+%-]+):(%d+):([%da-f%-]+):(%d+):([%w_]+)%]()") - end + local source, assoc_id, owner_ref, revision, code, encoded, boundary = string.match(comment, + header .. ":([%w_%-]+)%]()") + if not encoded then return end if not source or #source > 128 or not string.match(source, "^[%w]") or not restriction_labels[code] or #owner_ref ~= 36 or not string.match(owner_ref, "^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$") diff --git a/src/sai_compute_restrictions.py b/src/sai_compute_restrictions.py index f8561f4..58ac6f1 100644 --- a/src/sai_compute_restrictions.py +++ b/src/sai_compute_restrictions.py @@ -32,10 +32,10 @@ def _time(value: object) -> int: _PREFIX = "[sai.account-state/" _MARKER = re.compile( - r"\[sai\.account-state/(v[12]):([A-Za-z0-9][A-Za-z0-9_.+\-]{0,127}):" + r"\[sai\.account-state/v2:([A-Za-z0-9][A-Za-z0-9_.+\-]{0,127}):" r"([1-9][0-9]{0,9}):([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}):" r"([1-9][0-9]{0,18}):(open|arrears|severe_arrears|no_compute_funding|admin_blocked)" - r"(?::([A-Za-z0-9_-]+))?\]" + r":([A-Za-z0-9_-]+)\]" ) ASSOCIATION_BATCH_SIZE = 512 _LIMIT_FIELDS = {"billing_tres_limit": 2**64 - 3, "max_submit_jobs": 2**32 - 3} @@ -181,18 +181,12 @@ def decode_association_comment(comment: object) -> dict[str, Any] | None: match = _MARKER.match(comment) if match is None or (match.end() < len(comment) and comment[match.end()] != " "): raise ValueError("invalid managed association prefix") - version, account, association_id, owner_ref, revision, reason, encoded = match.groups() + account, association_id, owner_ref, revision, reason, encoded = match.groups() association_id, revision = int(association_id), int(revision) if association_id >= 2**32 - 2 or revision > 2**63 - 1: raise ValueError("invalid managed association generation") result = {"account": account, "association_id": association_id, "owner_ref": owner_ref, "revision": revision, "reason": None if reason == "open" else reason} - if version == "v1": - if encoded is not None: - raise ValueError("invalid v1 association metadata") - return result - if encoded is None: - raise ValueError("missing v2 association metadata") try: decoded = base64.b64decode(encoded + "=" * (-len(encoded) % 4), altchars=b"-_", validate=True) metadata = _metadata(json.loads(decoded.decode("ascii"))) @@ -214,24 +208,20 @@ def strip_association_comment(comment: str | None) -> str: def encode_association_comment(comment: str | None, *, account: str, association_id: int, - owner_ref: str, revision: int, reason: str | None, - limits: object = _OMITTED, ancestor_ids: object = _OMITTED, + owner_ref: str, revision: int, reason: str | None, limits: object, + ancestor_ids: object = _OMITTED, member: object = _OMITTED, applied: object = _OMITTED) -> str: account = _name(account) validate_reason(reason) if type(association_id) is not int or type(revision) is not int: raise ValueError("invalid managed association generation") - version, suffix = "v1", "" - if any(value is not _OMITTED for value in (limits, ancestor_ids, member, applied)): - metadata = {"limits": {} if limits is _OMITTED else limits, - "ancestor_ids": [] if ancestor_ids is _OMITTED else ancestor_ids, - "member": None if member is _OMITTED else member} - if applied is not _OMITTED: - metadata["applied"] = applied - metadata = _metadata(metadata) - suffix = ":" + base64.urlsafe_b64encode(_canonical(metadata)).rstrip(b"=").decode("ascii") - version = "v2" - prefix = f"{_PREFIX}{version}:{account}:{association_id}:{owner_ref}:{revision}:{reason or 'open'}{suffix}]" + metadata = {"limits": limits, "ancestor_ids": [] if ancestor_ids is _OMITTED else ancestor_ids, + "member": None if member is _OMITTED else member} + if applied is not _OMITTED: + metadata["applied"] = applied + metadata = _metadata(metadata) + encoded = base64.urlsafe_b64encode(_canonical(metadata)).rstrip(b"=").decode("ascii") + prefix = f"{_PREFIX}v2:{account}:{association_id}:{owner_ref}:{revision}:{reason or 'open'}:{encoded}]" decode_association_comment(prefix) note = strip_association_comment(comment) value = prefix + (" " + note if note else "") @@ -356,7 +346,7 @@ def _applied_matches(row: dict[str, Any], lineage: list[str], marker: dict[str, def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object], *, cluster: str, fetch, now: float | None = None) -> list[dict[str, Any]]: - """Read visible job associations and their applied records; old v2 reads parents.""" + """Read visible associations and applied records; v2 without a record reads parents.""" _name(cluster) if len(jobs) != len(association_ids): raise ValueError("job association bindings are incomplete") @@ -374,11 +364,10 @@ def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object], if marker is not None: if marker["account"] not in lineage or marker.get("limits"): raise ValueError("account context is outside the observed association lineage") - if "ancestor_ids" in marker: - if len(marker["ancestor_ids"]) != len(lineage) or row["id"] in marker["ancestor_ids"]: - raise ValueError("native association ancestry changed") - if "applied" not in marker: - ancestor_ids.extend(marker["ancestor_ids"]) + if len(marker["ancestor_ids"]) != len(lineage) or row["id"] in marker["ancestor_ids"]: + raise ValueError("native association ancestry changed") + if "applied" not in marker: + ancestor_ids.extend(marker["ancestor_ids"]) prepared[index] = row, lineage, marker parents = _association_rows(list(dict.fromkeys(ancestor_ids)), cluster=cluster, fetch=fetch) results = [{} for _ in jobs] @@ -404,7 +393,7 @@ def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object], current_parents.append((parent, _parent_marker(parent), association_limit_values(parent))) reason = jobs[index]["reason_or_nodelist"] if reason == "AssocGrpJobsLimit" and marker is not None and marker["reason"] is not None: - verified = "ancestor_ids" not in marker or any( + verified = any( parent["id"] == marker["association_id"] and source is not None and all(source[key] == marker[key] for key in ("account", "owner_ref", "revision", "reason")) and numeric["group_jobs_limit"] == 0 diff --git a/tests/test_compute_restrictions.py b/tests/test_compute_restrictions.py index d8ece28..87732c8 100644 --- a/tests/test_compute_restrictions.py +++ b/tests/test_compute_restrictions.py @@ -7,9 +7,19 @@ OWNER = "11111111-2222-4333-8444-555555555555" -def encoded(note="", reason="arrears", revision=1): - return encode_association_comment(note, account="org-a", association_id=3, - owner_ref=OWNER, revision=revision, reason=reason) +def encoded(note="", reason="arrears", revision=1, *, account="org-a", leaf="project-a", user="alice"): + lineage = f"/{account}/{leaf}/0-{user}/" + parents = [] + for ident, name in ((1, "root"), (3, account), (4, leaf)): + owned = ident == 3 + parents.append({"account": name, "association_id": ident, + "owner_ref": OWNER if owned else None, "revision": revision if owned else None, + "reason": reason if owned else None, "limits": {}, + "numeric": {"group_jobs_limit": 0 if owned and reason else None, + "billing_tres_limit": None, "max_submit_jobs": None}}) + return encode_association_comment(note, account=account, association_id=3, + owner_ref=OWNER, revision=revision, reason=reason, limits={}, ancestor_ids=[1, 3, 4], + applied={"recorded_at": 100, "association_id": 47, "lineage": lineage, "parents": parents}) def test_reason_changes_and_open_preserve_original_note_exactly(): @@ -18,12 +28,26 @@ def test_reason_changes_and_open_preserve_original_note_exactly(): second = encoded(first, "admin_blocked", 2) cleared = encoded(second, None, 3) assert strip_association_comment(first) == strip_association_comment(second) == strip_association_comment(cleared) == note - assert decode_association_comment(second) == {"account": "org-a", "association_id": 3, - "owner_ref": OWNER, "revision": 2, "reason": "admin_blocked"} + marker = decode_association_comment(second) + assert second.startswith("[sai.account-state/v2:") + assert {key: marker[key] for key in ("account", "association_id", "owner_ref", "revision", "reason")} == { + "account": "org-a", "association_id": 3, "owner_ref": OWNER, "revision": 2, "reason": "admin_blocked"} + assert encode_association_comment(second, **marker) == second assert decode_association_comment(cleared)["reason"] is None assert strip_association_comment("ordinary [brackets] note") == "ordinary [brackets] note" +def test_retired_prefix_is_rejected_and_encoder_requires_explicit_limits(): + old = f"[sai.account-state/v1:org-a:3:{OWNER}:1:arrears] manual note" + for read in (decode_association_comment, strip_association_comment, encoded): + with pytest.raises(ValueError): + read(old) + with pytest.raises(TypeError): + encode_association_comment("note", account="org-a", association_id=3, + owner_ref=OWNER, revision=1, reason="arrears") + assert decode_association_comment("manual " + old) is None + + def test_visible_page_deduplicates_native_read_and_existing_job_sees_reason_change(): job = {"state": "PD", "reason_or_nodelist": "AssocGrpJobsLimit", "slurm_account": "project-a", "slurm_user": "alice", "partition": "gpu"} @@ -39,7 +63,8 @@ def fetch(ids): result = read_job_contexts([job, job, {**job, "state": "R"}], [47, 47, 99], cluster="cluster-a", fetch=fetch, now=123) expected = {} if reason is None else {"account_restriction": { - "code": reason, "account": "org-a", "source": "sai_applied_policy", "observed_at": 123}} + "code": reason, "account": "org-a", "source": "sai_applied_policy", "observed_at": 123, + "basis": "applied_record", "recorded_at": 100}} assert result == [expected, expected, {}] assert calls == [[47]] * 3 and job == before assert read_job_contexts([{**job, "reason_or_nodelist": "Resources"}], [47], cluster="cluster-a", fetch=fetch) == [{}] diff --git a/tests/test_job_pending_reason.py b/tests/test_job_pending_reason.py index 56640b2..0c7cf5b 100644 --- a/tests/test_job_pending_reason.py +++ b/tests/test_job_pending_reason.py @@ -16,15 +16,15 @@ from sai_cli.tui import QueryApp from sai_cli.tui_queries import Queries from sai_compute_restrictions import encode_association_comment +from test_compute_restrictions import encoded from test_local_jobs import native_client, native_job, invoke, number from test_native_topology import topology_client from test_site_transport import http_endpoint, issuer, profile, invoke as invoke_remote, site_payload from test_tui import loaded -def association_comment(reason, revision=1): - return encode_association_comment("private operator note", account="org-parent", association_id=3, - owner_ref="11111111-2222-4333-8444-555555555555", revision=revision, reason=reason) +def association_comment(reason, revision=1, *, user): + return encoded("private operator note", reason, revision, account="org-parent", leaf="research", user=user) @pytest.fixture @@ -37,7 +37,7 @@ def native_associations(native_client): calls = source.parent / "association-calls.jsonl" value = {"associations": [{"id": 47, "cluster": "cluster-a", "account": job["account"], "user": job["user_name"], "partition": "", "lineage": f"/org-parent/research/0-{job['user_name']}/", - "comment": association_comment("arrears")}], "errors": []} + "comment": association_comment("arrears", user=job["user_name"])}], "errors": []} path.write_text(json.dumps(value)) binary = source.parent / "sacctmgr" binary.write_text(f"#!{sys.executable}\n" + f''' @@ -64,7 +64,7 @@ def native_associations(native_client): def test_native_queue_and_exact_detail_keep_separate_account_context(topology_client, native_associations, code, label): env, path, payload = topology_client association_path, associations, reads = native_associations - associations["associations"][0]["comment"] = association_comment(code) + associations["associations"][0]["comment"] = association_comment(code, user=associations["associations"][0]["user"]) association_path.write_text(json.dumps(associations)) job = payload["jobs"][0] job.update(job_state=["PENDING"], state_reason="AssocGrpJobsLimit", @@ -78,7 +78,7 @@ def test_native_queue_and_exact_detail_keep_separate_account_context(topology_cl observed = row["account_restriction"]["observed_at"] assert started <= observed <= int(time.time()) assert row["account_restriction"] == {"code": code, "account": "org-parent", - "source": "sai_applied_policy", "observed_at": observed} + "source": "sai_applied_policy", "observed_at": observed, "basis": "applied_record", "recorded_at": 100} assert all(value not in output for value in ("private operator note", "association_id", "owner_ref")) assert "pending_reason" not in row assert row["slurm_account"] == "research" @@ -218,7 +218,7 @@ async def run(): await pilot.press("enter") await loaded(app, pilot) assert app._allocation_detail["job"]["account_restriction"]["account"] == "org-parent" - associations["associations"][0]["comment"] = association_comment(None, revision=2) + associations["associations"][0]["comment"] = association_comment(None, revision=2, user=job["user_name"]) association_path.write_text(json.dumps(associations)) await pilot.press("r") await loaded(app, pilot) @@ -335,7 +335,7 @@ def limits(billing, submit, sources): limits=limits(billing, submit, sources))}) user.update(max=values(64, 20), comment=encode_association_comment( "private member note", account="research", association_id=4, owner_ref=owner, - revision=1, reason=None, ancestor_ids=[1, 3, 4], + revision=1, reason=None, limits={}, ancestor_ids=[1, 3, 4], member={"association_id": user["id"], "owner_ref": owner, "revision": 1, "limits": limits(64, 20, member_sources)})) payload["associations"] = [user, root, *parents] diff --git a/tests/test_job_submit_lua.py b/tests/test_job_submit_lua.py index fb42ea5..2179254 100644 --- a/tests/test_job_submit_lua.py +++ b/tests/test_job_submit_lua.py @@ -483,12 +483,11 @@ def test_submit_callback_has_no_runtime_external_io() -> None: assert "package.loadlib" not in text -@pytest.mark.parametrize("version", (1, 2)) -def test_account_notice_reads_selected_native_association_without_runtime_io(tmp_path: Path, version: int) -> None: +def test_account_notice_reads_selected_native_association_without_runtime_io(tmp_path: Path) -> None: from sai_compute_restrictions import encode_association_comment marker = encode_association_comment("private note", account="org-example", association_id=3, owner_ref="11111111-2222-4333-8444-555555555555", revision=7, reason="arrears", - **({"ancestor_ids": [1, 3]} if version == 2 else {})) + limits={}, ancestor_ids=[1, 3]) run_lua(_prelude(_snapshot(tmp_path)) + "marker=" + json.dumps(marker) + "\n" + r''' dofile = function() error("callback attempted file I/O") end local job = new_job({account = "proj-research", assoc_comment = marker, tres_per_node = "gres/gpu:4", priority = 0}) @@ -512,14 +511,12 @@ def test_account_notice_reads_selected_native_association_without_runtime_io(tmp def test_missing_open_or_malformed_native_marker_preserves_submit_behavior(tmp_path: Path) -> None: from sai_compute_restrictions import encode_association_comment opened = encode_association_comment("note", account="org-example", association_id=3, - owner_ref="11111111-2222-4333-8444-555555555555", revision=8, reason=None) - opened_v2 = encode_association_comment(opened, account="org-example", association_id=3, owner_ref="11111111-2222-4333-8444-555555555555", revision=8, reason=None, - ancestor_ids=[1, 3]) + limits={}, ancestor_ids=[1, 3]) + retired = "[sai.account-state/v1:org-example:3:11111111-2222-4333-8444-555555555555:8:arrears] note" for comment in ("", "operator note", "[sai.account-state/v1:bad]", opened, - opened.replace(":open]", ":unknown]"), opened.replace(":3:", ":0:"), - opened_v2, opened.replace("/v1:", "/v2:"), - opened_v2.replace("/v2:", "/v3:")): + opened.replace(":open:", ":unknown:"), opened.replace(":3:", ":0:"), + retired, opened.replace("/v2:", "/v3:")): run_lua(_prelude(_snapshot(tmp_path)) + "marker=" + json.dumps(comment) + "\n" + r''' assert(slurm_job_submit(new_job({account="proj-research", assoc_comment=marker, tres_per_node="gres/gpu:4"}), {}, 1000) == slurm.SUCCESS) assert(not message_contains("SAI账户")) diff --git a/tests/test_local_jobs.py b/tests/test_local_jobs.py index 1afa2bb..ab0297b 100644 --- a/tests/test_local_jobs.py +++ b/tests/test_local_jobs.py @@ -259,7 +259,7 @@ def test_explicit_limit_is_reported_not_a_complete_queue(native_client): def test_current_account_reason_uses_one_native_association_read_after_limit(native_client, tmp_path): - from sai_compute_restrictions import encode_association_comment + from test_compute_restrictions import encoded env, source, payload = native_client job = payload['jobs'][0] job.update(job_state=['PENDING'], state_reason='AssocGrpJobsLimit', association_id=47) @@ -278,8 +278,7 @@ def test_current_account_reason_uses_one_native_association_read_after_limit(nat association = {'id': 47, 'cluster': 'cluster-a', 'account': 'research', 'user': job['user_name'], 'partition': '', 'lineage': f"/org-a/research/0-{job['user_name']}/"} for reason in ('arrears', 'admin_blocked', None): - association['comment'] = encode_association_comment('private note', account='org-a', association_id=3, - owner_ref='11111111-2222-4333-8444-555555555555', revision=1, reason=reason) + association['comment'] = encoded('private note', reason, account='org-a', leaf='research', user=job['user_name']) rows.write_text(json.dumps({'associations': [association], 'errors': []})) code, output, errors = invoke(env, 'jobs', 'local', '--limit', '1') assert code == 0 and not errors