test-base 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. test_base/__init__.py +20 -0
  2. test_base/adapters/__init__.py +354 -0
  3. test_base/adapters/base.py +263 -0
  4. test_base/adapters/canonical_json.py +1088 -0
  5. test_base/adapters/junit_xml.py +1272 -0
  6. test_base/api/__init__.py +0 -0
  7. test_base/api/app.py +314 -0
  8. test_base/api/deps.py +178 -0
  9. test_base/api/routes/__init__.py +0 -0
  10. test_base/api/routes/failures.py +104 -0
  11. test_base/api/routes/health.py +35 -0
  12. test_base/api/routes/imports.py +143 -0
  13. test_base/api/routes/queries.py +295 -0
  14. test_base/api/routes/retention.py +130 -0
  15. test_base/api/routes/runs.py +147 -0
  16. test_base/api/routes/server.py +65 -0
  17. test_base/api/routes/stream.py +117 -0
  18. test_base/api/schemas.py +390 -0
  19. test_base/api/security.py +183 -0
  20. test_base/cli/__init__.py +125 -0
  21. test_base/cli/commands/__init__.py +0 -0
  22. test_base/cli/commands/db.py +76 -0
  23. test_base/cli/commands/demo.py +103 -0
  24. test_base/cli/commands/formats.py +41 -0
  25. test_base/cli/commands/ingest.py +119 -0
  26. test_base/cli/commands/init.py +738 -0
  27. test_base/cli/commands/prune.py +146 -0
  28. test_base/cli/commands/publish.py +133 -0
  29. test_base/cli/commands/serve.py +118 -0
  30. test_base/cli/commands/token.py +97 -0
  31. test_base/cli/options.py +189 -0
  32. test_base/cli/render.py +223 -0
  33. test_base/config.py +519 -0
  34. test_base/demo/__init__.py +0 -0
  35. test_base/demo/evidence.py +447 -0
  36. test_base/demo/seed.py +628 -0
  37. test_base/domain/__init__.py +61 -0
  38. test_base/domain/events.py +422 -0
  39. test_base/domain/failures.py +327 -0
  40. test_base/domain/identity.py +205 -0
  41. test_base/domain/metrics.py +176 -0
  42. test_base/domain/models.py +947 -0
  43. test_base/domain/status.py +246 -0
  44. test_base/errors.py +136 -0
  45. test_base/logging.py +174 -0
  46. test_base/py.typed +0 -0
  47. test_base/sdk/__init__.py +28 -0
  48. test_base/sdk/client.py +607 -0
  49. test_base/service/__init__.py +0 -0
  50. test_base/service/bus.py +331 -0
  51. test_base/service/coalesce.py +133 -0
  52. test_base/service/imports.py +552 -0
  53. test_base/service/retention.py +640 -0
  54. test_base/service/runs.py +394 -0
  55. test_base/service/runtime.py +123 -0
  56. test_base/storage/__init__.py +41 -0
  57. test_base/storage/artifacts.py +347 -0
  58. test_base/storage/base.py +350 -0
  59. test_base/storage/db.py +595 -0
  60. test_base/storage/failures.py +321 -0
  61. test_base/storage/locks.py +104 -0
  62. test_base/storage/migrations/env.py +108 -0
  63. test_base/storage/migrations/script.py.mako +26 -0
  64. test_base/storage/migrations/versions/0001_initial.py +289 -0
  65. test_base/storage/migrations/versions/0002_retention_indexes.py +38 -0
  66. test_base/storage/migrations/versions/0003_postgresql_bigint.py +74 -0
  67. test_base/storage/migrations/versions/0004_run_shards.py +37 -0
  68. test_base/storage/migrations/versions/0005_failure_groups.py +206 -0
  69. test_base/storage/models.py +560 -0
  70. test_base/storage/repositories.py +2481 -0
  71. test_base/storage/uow.py +138 -0
  72. test_base/version.py +17 -0
  73. test_base/web/assets/css/app.css +3567 -0
  74. test_base/web/assets/favicon.svg +5 -0
  75. test_base/web/assets/js/00-util.js +829 -0
  76. test_base/web/assets/js/05-windows.js +551 -0
  77. test_base/web/assets/js/10-provider.js +396 -0
  78. test_base/web/assets/js/12-live-provider.js +804 -0
  79. test_base/web/assets/js/20-charts.js +715 -0
  80. test_base/web/assets/js/30-store.js +793 -0
  81. test_base/web/assets/js/40-components.js +2141 -0
  82. test_base/web/assets/js/42-timeline.js +629 -0
  83. test_base/web/assets/js/50-view-overview.js +747 -0
  84. test_base/web/assets/js/52-view-analytics.js +842 -0
  85. test_base/web/assets/js/53-view-suites.js +508 -0
  86. test_base/web/assets/js/54-view-metrics.js +438 -0
  87. test_base/web/assets/js/55-view-runs.js +244 -0
  88. test_base/web/assets/js/56-view-evidence.js +703 -0
  89. test_base/web/assets/js/57-view-failures.js +596 -0
  90. test_base/web/assets/js/60-view-run.js +788 -0
  91. test_base/web/assets/js/65-view-test.js +402 -0
  92. test_base/web/assets/js/70-view-settings.js +524 -0
  93. test_base/web/assets/js/75-view-help.js +554 -0
  94. test_base/web/assets/js/80-settings.js +99 -0
  95. test_base/web/assets/js/85-activity.js +727 -0
  96. test_base/web/assets/js/90-app.js +595 -0
  97. test_base/web/assets/manifest.json +70 -0
  98. test_base/web/index.html +210 -0
  99. test_base-0.1.1.dist-info/METADATA +285 -0
  100. test_base-0.1.1.dist-info/RECORD +103 -0
  101. test_base-0.1.1.dist-info/WHEEL +4 -0
  102. test_base-0.1.1.dist-info/entry_points.txt +6 -0
  103. test_base-0.1.1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,76 @@
1
+ """``test-base db`` — which database Test Base is using, and whether it is ready.
2
+
3
+ The database is chosen with ``TEST_BASE_DATABASE_URL`` (or ``--database-url``):
4
+ unset is SQLite in the data directory, ``postgresql://…`` is PostgreSQL. These
5
+ two commands are how you check that the choice took::
6
+
7
+ test-base db check show the database, prove it answers, compare the schema
8
+ test-base db upgrade apply pending migrations now instead of on next start
9
+
10
+ ``serve``, ``ingest``, ``demo`` and ``prune`` all migrate on their own, so
11
+ ``upgrade`` is for when you want the schema change to be its own deliberate
12
+ step — a deploy pipeline that migrates before it rolls the new image out.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import typer
18
+
19
+ from test_base.cli.options import DatabaseUrlOption, DataDirOption, settings_from_cli
20
+
21
+ app = typer.Typer(
22
+ no_args_is_help=True,
23
+ help="Check the database Test Base is configured to use, and migrate it.",
24
+ )
25
+
26
+
27
+ @app.command("check", help="Show which database is configured and whether it is ready.")
28
+ def check(data_dir: DataDirOption = None, database_url: DatabaseUrlOption = None) -> None:
29
+ """Exit 0 when ready, 1 when migrations are pending, 78 when it cannot be reached."""
30
+ from test_base.storage import create_database
31
+
32
+ settings = settings_from_cli(data_dir=data_dir, database_url=database_url)
33
+ database = create_database(settings)
34
+ try:
35
+ typer.secho(f" database {database.display_url}", fg=typer.colors.CYAN)
36
+ database.ping()
37
+ typer.secho(f" server {database.server_version()}", fg=typer.colors.BRIGHT_BLACK)
38
+
39
+ current = database.current_revision()
40
+ head = database.head_revision()
41
+ if current is not None and current == head:
42
+ typer.secho(f" schema {current} (up to date)", fg=typer.colors.BRIGHT_BLACK)
43
+ typer.secho(" ready", fg=typer.colors.GREEN, bold=True)
44
+ return
45
+ if current is None:
46
+ typer.secho(" schema empty", fg=typer.colors.YELLOW)
47
+ else:
48
+ typer.secho(f" schema {current}, {head} available", fg=typer.colors.YELLOW)
49
+ typer.secho(
50
+ " run `test-base db upgrade` (serve also does it on start)", fg=typer.colors.YELLOW
51
+ )
52
+ finally:
53
+ database.dispose()
54
+ raise typer.Exit(1)
55
+
56
+
57
+ @app.command("upgrade", help="Apply any pending schema migrations now.")
58
+ def upgrade(data_dir: DataDirOption = None, database_url: DatabaseUrlOption = None) -> None:
59
+ """Bring the schema to head. Safe to run repeatedly, and from two places at once."""
60
+ from test_base.storage import create_database
61
+
62
+ settings = settings_from_cli(data_dir=data_dir, database_url=database_url)
63
+ database = create_database(settings)
64
+ try:
65
+ typer.secho(f" database {database.display_url}", fg=typer.colors.CYAN)
66
+ database.ping()
67
+ before = database.current_revision()
68
+ database.upgrade()
69
+ after = database.current_revision()
70
+ finally:
71
+ database.dispose()
72
+
73
+ if before == after:
74
+ typer.secho(f" schema already at {after}", fg=typer.colors.GREEN)
75
+ else:
76
+ typer.secho(f" schema {before or 'empty'} → {after}", fg=typer.colors.GREEN, bold=True)
@@ -0,0 +1,103 @@
1
+ """``test-base demo`` — fill the store with realistic sample data.
2
+
3
+ The fastest way to judge whether Test Base is worth adopting: run it, then
4
+ ``test-base serve``, and look at a populated dashboard rather than an empty one.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Annotated
10
+
11
+ import typer
12
+
13
+ from test_base.cli.options import (
14
+ DatabaseUrlOption,
15
+ DataDirOption,
16
+ settings_from_cli,
17
+ storage_location,
18
+ )
19
+
20
+
21
+ def demo(
22
+ days: Annotated[int, typer.Option("--days", help="How far back to spread the runs.")] = 14,
23
+ runs: Annotated[int, typer.Option("--runs", help="Runs per project.")] = 6,
24
+ live: Annotated[
25
+ bool, typer.Option("--live/--no-live", help="Include one run that is still going.")
26
+ ] = True,
27
+ data_dir: DataDirOption = None,
28
+ database_url: DatabaseUrlOption = None,
29
+ reset: Annotated[
30
+ bool,
31
+ typer.Option(
32
+ "--reset",
33
+ help="Delete the existing data first (on PostgreSQL: drop Test Base's tables).",
34
+ ),
35
+ ] = False,
36
+ ) -> None:
37
+ """Populate the store with realistic sample data."""
38
+ from test_base.demo.seed import seed_demo
39
+ from test_base.service.runtime import create_context
40
+
41
+ settings = settings_from_cli(data_dir=data_dir, database_url=database_url)
42
+
43
+ if reset and settings.database_backend == "sqlite":
44
+ database_file = settings.data_dir / "test-base.db"
45
+ removed = 0
46
+ for suffix in ("", "-wal", "-shm"):
47
+ candidate = database_file.with_name(database_file.name + suffix)
48
+ if candidate.exists():
49
+ candidate.unlink()
50
+ removed += 1
51
+ if removed:
52
+ typer.secho(
53
+ f" removed the existing database ({removed} file(s))", fg=typer.colors.YELLOW
54
+ )
55
+ elif reset:
56
+ # A server has no file to delete, and dropping the whole database would
57
+ # take anything else in it along. Drop Test Base's own tables instead;
58
+ # create_context below migrates them back from nothing.
59
+ from test_base.storage import create_database
60
+
61
+ database = create_database(settings)
62
+ try:
63
+ database.ping()
64
+ database.drop_schema()
65
+ finally:
66
+ database.dispose()
67
+ typer.secho(
68
+ f" dropped the existing Test Base tables in {database.display_url}",
69
+ fg=typer.colors.YELLOW,
70
+ )
71
+
72
+ context = create_context(settings)
73
+ try:
74
+ typer.echo()
75
+ typer.secho(" seeding sample data…", fg=typer.colors.BRIGHT_BLACK)
76
+ result = seed_demo(context, days=days, runs_per_project=runs, include_live_run=live)
77
+ finally:
78
+ context.close()
79
+
80
+ typer.echo()
81
+ typer.secho(" sample data created", fg=typer.colors.GREEN, bold=True)
82
+ typer.secho(
83
+ f" {result.projects} projects, {result.runs} runs, "
84
+ f"{result.tests} test results, {result.attempts} attempts",
85
+ fg=typer.colors.BRIGHT_BLACK,
86
+ )
87
+ typer.secho(
88
+ f" {result.failures} failures and {result.flaky} flaky retries, "
89
+ f"so the red and amber states have something to show",
90
+ fg=typer.colors.BRIGHT_BLACK,
91
+ )
92
+ if result.artifacts:
93
+ typer.secho(
94
+ f" {result.artifacts} files attached — screenshots, request logs, "
95
+ f"coverage reports and a trace",
96
+ fg=typer.colors.BRIGHT_BLACK,
97
+ )
98
+ if result.live_run_id:
99
+ typer.secho(f" one run is still open: {result.live_run_id}", fg=typer.colors.BLUE)
100
+ typer.secho(f" stored in {storage_location(settings)}", fg=typer.colors.BRIGHT_BLACK)
101
+ typer.echo()
102
+ typer.secho(" next: test-base serve", fg=typer.colors.CYAN, bold=True)
103
+ typer.echo()
@@ -0,0 +1,41 @@
1
+ """``test-base formats`` — what this installation can parse.
2
+
3
+ Also the answer to "why did my file not import": the same list appears in the
4
+ error when auto-detection fails, so the terminal and the API agree.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ from typing import Annotated
11
+
12
+ import typer
13
+
14
+
15
+ def formats(
16
+ json_output: Annotated[bool, typer.Option("--json", help="Print as JSON.")] = False,
17
+ ) -> None:
18
+ """List the installed report adapters."""
19
+ from test_base.adapters import get_registry
20
+
21
+ rows = get_registry().describe()
22
+ if json_output:
23
+ typer.echo(json.dumps(rows, indent=2))
24
+ return
25
+
26
+ typer.echo()
27
+ typer.secho(f" {len(rows)} adapter(s) installed", bold=True)
28
+ typer.echo()
29
+ for row in rows:
30
+ typer.secho(f" {row['name']}", fg=typer.colors.CYAN, bold=True, nl=False)
31
+ typer.secho(f" {row.get('display_name', '')}", fg=typer.colors.BRIGHT_BLACK)
32
+ if row.get("description"):
33
+ typer.echo(f" {row['description']}")
34
+ extensions = ", ".join(row.get("extensions", [])) or "—"
35
+ typer.secho(f" extensions: {extensions}", fg=typer.colors.BRIGHT_BLACK)
36
+ typer.echo()
37
+ typer.secho(
38
+ " Force one with --format <name>. Add more by installing an adapter package.",
39
+ fg=typer.colors.BRIGHT_BLACK,
40
+ )
41
+ typer.echo()
@@ -0,0 +1,119 @@
1
+ """``test-base ingest`` — import a report into the local store.
2
+
3
+ The offline half of the pair. ``ingest`` writes straight to the local database;
4
+ ``publish`` sends the same file to a remote server. They take the same options on
5
+ purpose, so moving a script from a laptop to CI is a one-word change.
6
+
7
+ Several files land in one run, all or nothing.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import contextlib
13
+ import uuid
14
+ from pathlib import Path
15
+ from typing import Annotated
16
+
17
+ import typer
18
+
19
+ from test_base.cli.options import (
20
+ BranchOption,
21
+ CommitOption,
22
+ ComponentOption,
23
+ DatabaseUrlOption,
24
+ DataDirOption,
25
+ EnvironmentOption,
26
+ FormatOption,
27
+ ProjectOption,
28
+ RunKeyOption,
29
+ ShardOption,
30
+ TeamOption,
31
+ TestTypeOption,
32
+ TriggerOption,
33
+ exclusive_run,
34
+ parse_shard,
35
+ settings_from_cli,
36
+ storage_location,
37
+ )
38
+ from test_base.cli.render import render_import_result
39
+ from test_base.domain.models import RunContext, TestType, TriggerType
40
+
41
+
42
+ def ingest(
43
+ paths: Annotated[
44
+ list[Path],
45
+ typer.Argument(
46
+ help="Report files to import. Several land in one run, all or nothing.",
47
+ exists=True,
48
+ dir_okay=False,
49
+ readable=True,
50
+ ),
51
+ ],
52
+ project: ProjectOption,
53
+ team: TeamOption = None,
54
+ component: ComponentOption = None,
55
+ type: TestTypeOption = TestType.OTHER,
56
+ trigger: TriggerOption = TriggerType.LOCAL,
57
+ environment: EnvironmentOption = None,
58
+ branch: BranchOption = None,
59
+ commit: CommitOption = None,
60
+ framework: Annotated[str | None, typer.Option("--framework")] = None,
61
+ language: Annotated[str | None, typer.Option("--language")] = None,
62
+ pipeline_id: Annotated[str | None, typer.Option("--pipeline-id")] = None,
63
+ pipeline_url: Annotated[str | None, typer.Option("--pipeline-url")] = None,
64
+ name: Annotated[str | None, typer.Option("--name", help="Human-readable run name.")] = None,
65
+ tags: Annotated[str | None, typer.Option("--tags", help="Comma-separated tags.")] = None,
66
+ run_id: Annotated[
67
+ uuid.UUID | None,
68
+ typer.Option("--run-id", help="Import into an existing run instead of a new one."),
69
+ ] = None,
70
+ run_key: RunKeyOption = None,
71
+ shard: ShardOption = None,
72
+ format: FormatOption = None,
73
+ data_dir: DataDirOption = None,
74
+ database_url: DatabaseUrlOption = None,
75
+ json_output: Annotated[bool, typer.Option("--json", help="Print the result as JSON.")] = False,
76
+ ) -> None:
77
+ """Import report files into the local store."""
78
+ from test_base.service.imports import ImportRequest, ImportService, ImportUpload
79
+ from test_base.service.runtime import create_context
80
+
81
+ exclusive_run(run_id, run_key)
82
+ shard_ref = parse_shard(shard)
83
+ settings = settings_from_cli(data_dir=data_dir, database_url=database_url)
84
+ context = create_context(settings)
85
+ try:
86
+ service = ImportService(context)
87
+ request = ImportRequest(
88
+ project_key=project,
89
+ run_id=run_id,
90
+ name=name,
91
+ team=team,
92
+ component=component,
93
+ test_type=type,
94
+ trigger=trigger,
95
+ context=RunContext(
96
+ framework=framework,
97
+ language=language,
98
+ environment=environment,
99
+ branch=branch,
100
+ commit_sha=commit,
101
+ pipeline_id=pipeline_id,
102
+ pipeline_url=pipeline_url,
103
+ ),
104
+ tags=[tag.strip() for tag in (tags or "").split(",") if tag.strip()],
105
+ explicit_format=format,
106
+ source="urn:test-base:cli-ingest",
107
+ run_key=run_key,
108
+ shard=shard_ref,
109
+ )
110
+ with contextlib.ExitStack() as stack:
111
+ uploads = [
112
+ ImportUpload(stack.enter_context(path.open("rb")), filename=path.name)
113
+ for path in paths
114
+ ]
115
+ result = service.import_files(uploads, request)
116
+ finally:
117
+ context.close()
118
+
119
+ render_import_result(result, json_output=json_output, destination=storage_location(settings))