@flighthq/image 0.4.0-next.1903.50bfa67 → 0.4.0-next.1908.751021c

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/image",
3
- "version": "0.4.0-next.1903.50bfa67",
3
+ "version": "0.4.0-next.1908.751021c",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,9 +38,9 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/entity": "0.4.0-next.1903.50bfa67",
42
- "@flighthq/image-codec": "0.4.0-next.1903.50bfa67",
43
- "@flighthq/types": "0.4.0-next.1903.50bfa67"
41
+ "@flighthq/entity": "0.4.0-next.1908.751021c",
42
+ "@flighthq/image-codec": "0.4.0-next.1908.751021c",
43
+ "@flighthq/types": "0.4.0-next.1908.751021c"
44
44
  },
45
45
  "devDependencies": {
46
46
  "typescript": "^5.3.0"
@@ -1,7 +1,15 @@
1
1
  import type { Image, ImageBackend } from '@flighthq/types/contract';
2
2
  import { afterEach, describe, expect, it } from 'vitest';
3
3
 
4
- import { createWebImageBackend, getImageBackend, setImageBackend } from './imageBackend';
4
+ import {
5
+ createWebImageBackend,
6
+ getImageBackend,
7
+ setImageBackend,
8
+ explainImageBackend,
9
+ installImageHostBackend,
10
+ observeImageHostResult,
11
+ resetImageBackendForTest,
12
+ } from './imageBackend';
5
13
  import { loadImageResourceFromUrl } from './imageResourceFrom';
6
14
 
7
15
  // Every test that installs a backend must put it back, or a later test sees a stale one.
@@ -32,6 +40,34 @@ describe('createWebImageBackend', () => {
32
40
  });
33
41
  });
34
42
 
43
+ describe('explainImageBackend', () => {
44
+ afterEach(() => resetImageBackendForTest());
45
+
46
+ it('reports host-not-enabled when no backend is installed', () => {
47
+ resetImageBackendForTest();
48
+ const explanation = explainImageBackend();
49
+ expect(explanation.layer).toBe('host-not-enabled');
50
+ expect(explanation.conflict).toBe(false);
51
+ expect(explanation.viability).toBe('unobserved');
52
+ });
53
+
54
+ it('reports custom layer when a custom backend is set', () => {
55
+ setImageBackend(getImageBackend());
56
+ expect(explainImageBackend().layer).toBe('custom');
57
+ });
58
+
59
+ it('reports host layer when a host backend is installed', () => {
60
+ installImageHostBackend(getImageBackend());
61
+ expect(explainImageBackend().layer).toBe('host');
62
+ });
63
+
64
+ it('reports conflict when two different host backends are installed', () => {
65
+ installImageHostBackend({ ...getImageBackend() });
66
+ installImageHostBackend({ ...getImageBackend() });
67
+ expect(explainImageBackend().conflict).toBe(true);
68
+ });
69
+ });
70
+
35
71
  describe('getImageBackend', () => {
36
72
  it('defaults lazily to a web backend rather than being registered at import', () => {
37
73
  expect(typeof getImageBackend().loadImageFromUrl).toBe('function');
@@ -48,6 +84,55 @@ describe('getImageBackend', () => {
48
84
  });
49
85
  });
50
86
 
87
+ describe('installImageHostBackend', () => {
88
+ afterEach(() => resetImageBackendForTest());
89
+
90
+ it('installs a host backend that getImageBackend returns', () => {
91
+ const backend = getImageBackend();
92
+ installImageHostBackend(backend);
93
+ expect(getImageBackend()).toBe(backend);
94
+ });
95
+
96
+ it('is first-host-wins: a second different backend sets conflict', () => {
97
+ const first = { ...getImageBackend() };
98
+ const second = { ...getImageBackend() };
99
+ installImageHostBackend(first);
100
+ installImageHostBackend(second);
101
+ expect(getImageBackend()).toBe(first);
102
+ expect(explainImageBackend().conflict).toBe(true);
103
+ });
104
+ });
105
+
106
+ describe('observeImageHostResult', () => {
107
+ afterEach(() => resetImageBackendForTest());
108
+
109
+ it('records a successful observation', () => {
110
+ installImageHostBackend(getImageBackend());
111
+ observeImageHostResult('loadImageFromUrl', true);
112
+ const explanation = explainImageBackend();
113
+ expect(explanation.operation).toBe('loadImageFromUrl');
114
+ expect(explanation.viability).toBe('available');
115
+ });
116
+
117
+ it('records a failed observation', () => {
118
+ installImageHostBackend(getImageBackend());
119
+ observeImageHostResult('loadImageFromUrl', false);
120
+ expect(explainImageBackend().viability).toBe('runtime-api-unavailable');
121
+ });
122
+ });
123
+
124
+ describe('resetImageBackendForTest', () => {
125
+ it('clears all backend slots', () => {
126
+ setImageBackend(getImageBackend());
127
+ installImageHostBackend(getImageBackend());
128
+ observeImageHostResult('loadImageFromUrl', true);
129
+ resetImageBackendForTest();
130
+ expect(explainImageBackend().layer).toBe('host-not-enabled');
131
+ expect(explainImageBackend().conflict).toBe(false);
132
+ expect(explainImageBackend().viability).toBe('unobserved');
133
+ });
134
+ });
135
+
51
136
  describe('setImageBackend', () => {
52
137
  it('restores a working web default when passed null, rather than leaving a one-way door', () => {
53
138
  const { backend } = recordingBackend();