dependency-contract.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { describe, expect, test } from 'bun:test';
  2. type PackageManifest = {
  3. dependencies?: Record<string, string>;
  4. optionalDependencies?: Record<string, string>;
  5. peerDependencies?: Record<string, string>;
  6. version?: string;
  7. };
  8. async function readManifest(relativePath: string): Promise<PackageManifest> {
  9. return (await Bun.file(
  10. new URL(relativePath, import.meta.url),
  11. ).json()) as PackageManifest;
  12. }
  13. const rootManifest = await readManifest('../package.json');
  14. const openCodePluginManifest = await readManifest(
  15. '../node_modules/@opencode-ai/plugin/package.json',
  16. );
  17. const openTuiSolidManifest = await readManifest(
  18. '../node_modules/@opentui/solid/package.json',
  19. );
  20. describe('dependency compatibility contract', () => {
  21. test('keeps OpenCode plugin and SDK on one exact version', () => {
  22. const pluginVersion = rootManifest.dependencies?.['@opencode-ai/plugin'];
  23. const sdkVersion = rootManifest.dependencies?.['@opencode-ai/sdk'];
  24. expect(pluginVersion).toBeDefined();
  25. expect(pluginVersion).toBe(sdkVersion);
  26. expect(openCodePluginManifest.version).toBe(pluginVersion);
  27. expect(openCodePluginManifest.dependencies?.['@opencode-ai/sdk']).toBe(
  28. sdkVersion,
  29. );
  30. });
  31. test('pins one compatible OpenTUI and Solid family', () => {
  32. const coreVersion = rootManifest.optionalDependencies?.['@opentui/core'];
  33. const solidVersion = rootManifest.optionalDependencies?.['@opentui/solid'];
  34. const solidJsVersion = rootManifest.optionalDependencies?.['solid-js'];
  35. expect(coreVersion).toBeDefined();
  36. expect(coreVersion).toBe(solidVersion);
  37. expect(openTuiSolidManifest.version).toBe(solidVersion);
  38. expect(openTuiSolidManifest.dependencies?.['@opentui/core']).toBe(
  39. coreVersion,
  40. );
  41. expect(openTuiSolidManifest.peerDependencies?.['solid-js']).toBe(
  42. solidJsVersion,
  43. );
  44. for (const packageName of ['@opentui/core', '@opentui/solid']) {
  45. const peerRange = openCodePluginManifest.peerDependencies?.[packageName];
  46. const installedVersion = rootManifest.optionalDependencies?.[packageName];
  47. expect(peerRange).toBeDefined();
  48. expect(installedVersion).toBeDefined();
  49. expect(
  50. Bun.semver.satisfies(installedVersion ?? '', peerRange ?? ''),
  51. ).toBe(true);
  52. }
  53. });
  54. });