@biffo/cli 0.339.0 → 0.341.0

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 (2) hide show
  1. package/dist/index.js +89 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -262,7 +262,14 @@ var CoreManifestSchema2 = z2.object({
262
262
  * template-owned change", the release job would cut nothing, and the fix
263
263
  * would never reach npm for any instance to install.
264
264
  */
265
- released: z2.array(z2.string()).default([])
265
+ released: z2.array(z2.string()).default([]),
266
+ /**
267
+ * Seed mode: exact repo-relative files the template ships as a one-time
268
+ * scaffold into a USER-OWNED location (they must also be user-owned, e.g.
269
+ * under `infra/`). `biffo core upgrade` creates one only when absent from the
270
+ * instance and never overwrites or deletes it afterwards.
271
+ */
272
+ seeded: z2.array(z2.string()).default([])
266
273
  });
267
274
  var HARD_EXCLUDED_DIRS = /* @__PURE__ */ new Set([
268
275
  ".git",
@@ -1040,6 +1047,22 @@ function applyUpgradePlan(instanceDir, plan, theirsDir) {
1040
1047
  }
1041
1048
  return { written, deleted };
1042
1049
  }
1050
+ function pendingSeeds(instanceDir, theirsDir, seeded) {
1051
+ return seeded.filter(
1052
+ (rel) => existsSync5(join5(theirsDir, rel)) && !existsSync5(join5(instanceDir, rel))
1053
+ );
1054
+ }
1055
+ function seedMissingFiles(instanceDir, theirsDir, seeded) {
1056
+ const created = [];
1057
+ for (const rel of pendingSeeds(instanceDir, theirsDir, seeded)) {
1058
+ const src = join5(theirsDir, rel);
1059
+ const dest = join5(instanceDir, rel);
1060
+ mkdirSync(dirname3(dest), { recursive: true });
1061
+ writeFileSync2(dest, readFileSync4(src));
1062
+ created.push(rel);
1063
+ }
1064
+ return created;
1065
+ }
1043
1066
  var ORPHAN_BASELINE_FILE = "biffo.orphan-baseline.json";
1044
1067
  var OrphanBaselineSchema = z4.object({
1045
1068
  count: z4.number().int().min(0)
@@ -3487,7 +3510,10 @@ var REGISTERED_ADOPTION_PAIRS = [
3487
3510
  templateFile: "infra/environments/dev/core-api.core.tf",
3488
3511
  userFile: "infra/environments/dev/main.tf",
3489
3512
  adoptedPattern: new RegExp(NO_CORE_API_MODULE_SOURCE, "m"),
3490
- remedy: 'Run `biffo core upgrade` to receive `core-api.core.tf` (or equivalent), then delete the `module "core_api" { ... }` block from infra/environments/dev/main.tf (first move instance-only environment variables into `local.core_api_instance_environment` in infra/environments/dev/core-api.instance.tf, and memory/SnapStart/timeout into terraform.tfvars as `core_api_memory_size` / `core_api_enable_warm_capacity` / `core_api_timeout`), then run `terraform plan` and confirm module.core_api shows no changes to destroy/create.'
3513
+ // core-api.core.tf references local.core_api_instance_environment, which is
3514
+ // declared only in this user-owned, upgrade-seeded file.
3515
+ requiredInstanceFile: "infra/environments/dev/core-api.instance.tf",
3516
+ remedy: 'Run `biffo core upgrade` to receive `core-api.core.tf` and to seed infra/environments/dev/core-api.instance.tf if it is missing (core-api.core.tf references `local.core_api_instance_environment`, declared only there), then delete the `module "core_api" { ... }` block from infra/environments/dev/main.tf (first move instance-only environment variables into `local.core_api_instance_environment` in infra/environments/dev/core-api.instance.tf, and memory/SnapStart/timeout into terraform.tfvars as `core_api_memory_size` / `core_api_enable_warm_capacity` / `core_api_timeout`), then run `terraform plan` and confirm module.core_api shows no changes to destroy/create.'
3491
3517
  }
3492
3518
  ];
3493
3519
  function isAdopted(pair, userFileContent) {
@@ -3506,7 +3532,11 @@ function checkInstanceAdoption(theirsDir, oursDir, pairs = REGISTERED_ADOPTION_P
3506
3532
  applicablePairs++;
3507
3533
  const userPath = join11(oursDir, pair.userFile);
3508
3534
  const content = existsSync10(userPath) ? readFileSync8(userPath, "utf8") : null;
3509
- findings.push({ pair, status: isAdopted(pair, content) ? "adopted" : "unadopted" });
3535
+ const scaffoldMissing = pair.requiredInstanceFile !== void 0 && existsSync10(join11(theirsDir, pair.requiredInstanceFile)) && !existsSync10(join11(oursDir, pair.requiredInstanceFile));
3536
+ findings.push({
3537
+ pair,
3538
+ status: !scaffoldMissing && isAdopted(pair, content) ? "adopted" : "unadopted"
3539
+ });
3510
3540
  }
3511
3541
  return {
3512
3542
  examinedInstances: 1,
@@ -4224,7 +4254,8 @@ async function runCoreUpgradeResolved(options, deps, cleanups) {
4224
4254
  );
4225
4255
  }
4226
4256
  const coreVersionCleanup = planCoreVersionCleanup(options.cwd);
4227
- if (plan.changes.length === 0 && migrations.entries.length === 0) {
4257
+ const seedsPending = pendingSeeds(options.cwd, theirsDir, manifest.seeded);
4258
+ if (plan.changes.length === 0 && migrations.entries.length === 0 && seedsPending.length === 0) {
4228
4259
  log.success("Nothing to upgrade \u2014 the instance already matches the target for all core files.");
4229
4260
  return;
4230
4261
  }
@@ -4351,6 +4382,10 @@ async function buildCommitAndOpenPr(options, deps, plan, migrations, fromVersion
4351
4382
  const { git } = deps;
4352
4383
  const applied = applyUpgradePlan(options.cwd, plan, theirsDir);
4353
4384
  const carried = applyMigrationCarry(options.cwd, migrations);
4385
+ const seeded = seedMissingFiles(options.cwd, theirsDir, readCoreManifest(theirsDir).seeded);
4386
+ for (const f of seeded) {
4387
+ log.info(`Seeded ${f} (user-owned scaffold; created because it was absent, never overwritten).`);
4388
+ }
4354
4389
  writeInstanceCoreVersion(options.cwd, toVersion);
4355
4390
  const establishedOrphanBaseline = orphanRatchet.baseline === null;
4356
4391
  if (establishedOrphanBaseline) {
@@ -7262,6 +7297,44 @@ generated = sync_plugin_migrations(migrations / "versions", services_root=servic
7262
7297
  print(f"bootstrap: generated {len(generated)} plugin migration(s)", flush=True)
7263
7298
  cfg = Config(str(Path.cwd() / "alembic.ini"))
7264
7299
  cfg.set_main_option("script_location", str(migrations))
7300
+
7301
+ # \`plugin verify\` provisions the plugin's manifest tables before Core boots, so the generated
7302
+ # plugin migration (plain op.create_table) would collide with them. Make table/column/index
7303
+ # creation idempotent for this disposable bootstrap run only.
7304
+ import sqlalchemy as sa # noqa: E402
7305
+ from alembic import op # noqa: E402
7306
+
7307
+ _create_table, _create_index, _add_column = op.create_table, op.create_index, op.add_column
7308
+ _skipped_tables: set = set()
7309
+
7310
+
7311
+ def _insp():
7312
+ return sa.inspect(op.get_bind())
7313
+
7314
+
7315
+ def _create_table_if_absent(name, *args, **kw):
7316
+ if _insp().has_table(name, schema=kw.get("schema")):
7317
+ _skipped_tables.add(name)
7318
+ return None
7319
+ return _create_table(name, *args, **kw)
7320
+
7321
+
7322
+ def _create_index_if_absent(name, table, *args, **kw):
7323
+ if table in _skipped_tables:
7324
+ return None
7325
+ return _create_index(name, table, *args, **kw)
7326
+
7327
+
7328
+ def _add_column_if_absent(table, column, **kw):
7329
+ if any(c["name"] == column.name for c in _insp().get_columns(table, schema=kw.get("schema"))):
7330
+ return None
7331
+ return _add_column(table, column, **kw)
7332
+
7333
+
7334
+ op.create_table = _create_table_if_absent
7335
+ op.create_index = _create_index_if_absent
7336
+ op.add_column = _add_column_if_absent
7337
+
7265
7338
  command.upgrade(cfg, "head")
7266
7339
  print("bootstrap: alembic upgrade head complete", flush=True)
7267
7340
  `;
@@ -12708,10 +12781,21 @@ from alembic import context
12708
12781
  from sqlalchemy.ext.asyncio import create_async_engine
12709
12782
 
12710
12783
 
12784
+ PLUGIN_VERSION_TABLE = "alembic_version_plugin_manifest"
12785
+
12786
+
12711
12787
  async def run() -> None:
12712
12788
  engine = create_async_engine(os.environ["BIFFO_DATABASE_URL"])
12713
12789
  async with engine.connect() as connection:
12714
- await connection.run_sync(lambda c: context.configure(connection=c, target_metadata=None))
12790
+ await connection.run_sync(lambda c: context.configure(
12791
+ connection=c,
12792
+ target_metadata=None,
12793
+ # Own version table: the default \`alembic_version\` is Core's, and a plugin-only
12794
+ # revision recorded there makes Core's own migrations look applied (or fail on
12795
+ # an unknown head) when Core boots, leaving its tables (users, ...) missing.
12796
+ version_table=PLUGIN_VERSION_TABLE,
12797
+ )
12798
+ )
12715
12799
  async with connection.begin():
12716
12800
  await connection.run_sync(lambda _: context.run_migrations())
12717
12801
  await engine.dispose()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.339.0",
3
+ "version": "0.341.0",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",