Publish Forge resource economics evidence
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02669-87ee-7a31-b111-edc95a16e0fa
This commit is contained in:
parent
a0f4c493a3
commit
35dbe4dd42
12 changed files with 632 additions and 30 deletions
33
tests/test_forge_resources.py
Normal file
33
tests/test_forge_resources.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SPEC = importlib.util.spec_from_file_location("forge_resources", ROOT / "tools" / "observe_forge_resources.py")
|
||||
assert SPEC and SPEC.loader
|
||||
module = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(module)
|
||||
|
||||
|
||||
class ForgeResourceTests(unittest.TestCase):
|
||||
def test_resource_aggregation_and_residual(self) -> None:
|
||||
deployment = {"metadata": {"name": "forgejo-gitea"}, "spec": {"replicas": 1, "template": {"spec": {"containers": [{"resources": {"requests": {"cpu": "100m", "memory": "128Mi"}, "limits": {"cpu": "1", "memory": "1Gi"}}}]}}}, "status": {"availableReplicas": 1}}
|
||||
snapshot = {
|
||||
"deployments": {"items": [deployment]},
|
||||
"pvcs": {"items": [{"metadata": {"name": "data"}, "spec": {"storageClassName": "local-path", "resources": {"requests": {"storage": "10Gi"}}}, "status": {"phase": "Bound"}}]},
|
||||
"database": {"spec": {"instances": 1, "storage": {"size": "10Gi"}}, "status": {"readyInstances": 1, "phase": "ready", "conditions": []}},
|
||||
"backups": {"items": []},
|
||||
"top": None,
|
||||
"forge_data_kib": 1024,
|
||||
"runner_data_kib": None,
|
||||
}
|
||||
result = module.build_observation(snapshot, "2026-08-22T00:00:00Z")
|
||||
self.assertEqual(100, result["capacity"]["deployments"][0]["requests"]["cpu_millicores"])
|
||||
self.assertEqual(1024**2, result["allocation"]["residual"]["forge_data_used_bytes"])
|
||||
self.assertIn("forgejo-db has no Backup or ScheduledBackup evidence", result["measurement_gaps"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue