alessandro trinca tornidor
commited on
Commit
·
0034bb5
1
Parent(s):
cb40b21
ci: consistent management of DOMAIN variable between backend and frontend
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from fastapi.responses import FileResponse, JSONResponse
|
|
| 9 |
from fastapi.staticfiles import StaticFiles
|
| 10 |
import uvicorn
|
| 11 |
|
| 12 |
-
from my_ghost_writer.constants import ALLOWED_ORIGIN_LIST, IS_TESTING, LOG_LEVEL, STATIC_FOLDER, app_logger
|
| 13 |
from my_ghost_writer.type_hints import RequestTextFrequencyBody
|
| 14 |
|
| 15 |
|
|
@@ -87,7 +87,7 @@ def index() -> FileResponse:
|
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
try:
|
| 90 |
-
uvicorn.run("app:app", host=
|
| 91 |
except Exception as ex:
|
| 92 |
print(f"fastapi/gradio application {fastapi_title}, exception:{ex}!")
|
| 93 |
app_logger.exception(f"fastapi/gradio application {fastapi_title}, exception:{ex}!")
|
|
|
|
| 9 |
from fastapi.staticfiles import StaticFiles
|
| 10 |
import uvicorn
|
| 11 |
|
| 12 |
+
from my_ghost_writer.constants import ALLOWED_ORIGIN_LIST, DOMAIN, IS_TESTING, LOG_LEVEL, PORT, STATIC_FOLDER, app_logger
|
| 13 |
from my_ghost_writer.type_hints import RequestTextFrequencyBody
|
| 14 |
|
| 15 |
|
|
|
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
try:
|
| 90 |
+
uvicorn.run("app:app", host=DOMAIN, port=PORT, reload=bool(IS_TESTING))
|
| 91 |
except Exception as ex:
|
| 92 |
print(f"fastapi/gradio application {fastapi_title}, exception:{ex}!")
|
| 93 |
app_logger.exception(f"fastapi/gradio application {fastapi_title}, exception:{ex}!")
|
my_ghost_writer/constants.py
CHANGED
|
@@ -7,7 +7,9 @@ from my_ghost_writer import session_logger
|
|
| 7 |
|
| 8 |
PROJECT_ROOT_FOLDER = Path(__file__).parent.parent
|
| 9 |
STATIC_FOLDER = PROJECT_ROOT_FOLDER / "static"
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
LOG_JSON_FORMAT = bool(os.getenv("LOG_JSON_FORMAT"))
|
| 12 |
IS_TESTING = bool(os.getenv('IS_TESTING', ""))
|
| 13 |
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
|
|
|
|
| 7 |
|
| 8 |
PROJECT_ROOT_FOLDER = Path(__file__).parent.parent
|
| 9 |
STATIC_FOLDER = PROJECT_ROOT_FOLDER / "static"
|
| 10 |
+
DOMAIN=os.getenv("DOMAIN", "localhost")
|
| 11 |
+
PORT=os.getenv("PORT", 7860)
|
| 12 |
+
ALLOWED_ORIGIN_LIST = os.getenv('ALLOWED_ORIGIN', f'http://{DOMAIN}:{PORT}').split(",")
|
| 13 |
LOG_JSON_FORMAT = bool(os.getenv("LOG_JSON_FORMAT"))
|
| 14 |
IS_TESTING = bool(os.getenv('IS_TESTING', ""))
|
| 15 |
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
|
static/playwright.config.ts
CHANGED
|
@@ -26,7 +26,7 @@ export default defineConfig({
|
|
| 26 |
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
| 27 |
use: {
|
| 28 |
/* Base URL to use in actions like `await page.goto('/')`. */
|
| 29 |
-
baseURL: 'http://localhost:7860',
|
| 30 |
browserName: "chromium",
|
| 31 |
viewport: { width: 1600, height: 1200 },
|
| 32 |
ignoreHTTPSErrors: true,
|
|
|
|
| 26 |
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
| 27 |
use: {
|
| 28 |
/* Base URL to use in actions like `await page.goto('/')`. */
|
| 29 |
+
baseURL: process.env.DOMAIN_PORT ?? 'http://localhost:7860',
|
| 30 |
browserName: "chromium",
|
| 31 |
viewport: { width: 1600, height: 1200 },
|
| 32 |
ignoreHTTPSErrors: true,
|
static/template.env
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
|
| 2 |
ALLOWED_ORIGIN=http://localhost:7860,http://localhost:8000
|
|
|
|
| 1 |
+
DOMAIN_PORT=http://localhost:7860
|
| 2 |
ALLOWED_ORIGIN=http://localhost:7860,http://localhost:8000
|
static/tests/test-word-frequency-1.spec.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { fileReader, loopOverTablesAndClickOnUrls } from './test-helper'
|
|
| 5 |
test(`test: word frequency (short text input)`, async ({ page }) => {
|
| 6 |
const wordFreqTable0AriaSnapshot1FilePath = `${import.meta.dirname}/test-word-frequency-1-table0-aria-snapshot.txt`
|
| 7 |
const wordFreqTable13AriaSnapshot1FilePath = `${import.meta.dirname}/test-word-frequency-1-table13-aria-snapshot.txt`
|
| 8 |
-
await page.goto(process.env.
|
| 9 |
console.log(page.url())
|
| 10 |
|
| 11 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
|
@@ -28,7 +28,7 @@ test(`test: word frequency (short text input)`, async ({ page }) => {
|
|
| 28 |
|
| 29 |
test(`test: word frequency (long, multi line text input)`, async ({ page }) => {
|
| 30 |
const testLLMTextFilePath = `${import.meta.dirname}/../../tests/events/llm_generated_story_1.txt`
|
| 31 |
-
await page.goto(process.env.
|
| 32 |
console.log(page.url())
|
| 33 |
|
| 34 |
console.log("Let's try with a much longer, multiline text while scrolling the conteditable div on click")
|
|
|
|
| 5 |
test(`test: word frequency (short text input)`, async ({ page }) => {
|
| 6 |
const wordFreqTable0AriaSnapshot1FilePath = `${import.meta.dirname}/test-word-frequency-1-table0-aria-snapshot.txt`
|
| 7 |
const wordFreqTable13AriaSnapshot1FilePath = `${import.meta.dirname}/test-word-frequency-1-table13-aria-snapshot.txt`
|
| 8 |
+
await page.goto(process.env.DOMAIN_PORT ?? "/");
|
| 9 |
console.log(page.url())
|
| 10 |
|
| 11 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
|
|
|
| 28 |
|
| 29 |
test(`test: word frequency (long, multi line text input)`, async ({ page }) => {
|
| 30 |
const testLLMTextFilePath = `${import.meta.dirname}/../../tests/events/llm_generated_story_1.txt`
|
| 31 |
+
await page.goto(process.env.DOMAIN_PORT ?? "/");
|
| 32 |
console.log(page.url())
|
| 33 |
|
| 34 |
console.log("Let's try with a much longer, multiline text while scrolling the conteditable div on click")
|
static/tests/test-word-frequency-2-filtering-sorting.spec.ts
CHANGED
|
@@ -10,7 +10,7 @@ const expectedInitialCount = 14;
|
|
| 10 |
{count: expectedInitialCount, filter: "", testIdx: 2},
|
| 11 |
].forEach(({ count, filter, testIdx }) => {
|
| 12 |
test(`words frequency: filtering, ordering and sorting - ${testIdx}, sort/order ${sortOrder}.`, async ({ page }) => {
|
| 13 |
-
await page.goto(
|
| 14 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
| 15 |
let containerTable = page.getByLabel('words-frequency', { exact: true })
|
| 16 |
await page.waitForTimeout(100)
|
|
|
|
| 10 |
{count: expectedInitialCount, filter: "", testIdx: 2},
|
| 11 |
].forEach(({ count, filter, testIdx }) => {
|
| 12 |
test(`words frequency: filtering, ordering and sorting - ${testIdx}, sort/order ${sortOrder}.`, async ({ page }) => {
|
| 13 |
+
await page.goto(process.env.DOMAIN_PORT ?? "/");
|
| 14 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
| 15 |
let containerTable = page.getByLabel('words-frequency', { exact: true })
|
| 16 |
await page.waitForTimeout(100)
|
static/tests/test-word-frequency-3-sorting.spec.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { assertTableStap } from './test-helper'
|
|
| 5 |
const count = 14
|
| 6 |
test.describe(`word frequency: sorting output with ${14} tables`, () => {
|
| 7 |
test.beforeEach(async({page}) => {
|
| 8 |
-
await page.goto(
|
| 9 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
| 10 |
});
|
| 11 |
|
|
|
|
| 5 |
const count = 14
|
| 6 |
test.describe(`word frequency: sorting output with ${14} tables`, () => {
|
| 7 |
test.beforeEach(async({page}) => {
|
| 8 |
+
await page.goto(process.env.DOMAIN_PORT ?? "/");
|
| 9 |
await page.getByRole('button', { name: 'btn4-getWordFrequency' }).click();
|
| 10 |
});
|
| 11 |
|
template.env
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
-
DOMAIN=
|
|
|
|
| 2 |
ALLOWED_ORIGIN=http://localhost:7860,http://localhost:8000
|
|
|
|
| 1 |
+
DOMAIN=localhost
|
| 2 |
+
PORT=7860
|
| 3 |
ALLOWED_ORIGIN=http://localhost:7860,http://localhost:8000
|