netcreateorg / netcreate-itest

Developing the 2.0 version of NetCreate
https://github.com/netcreateorg/netcreate-2018
Other
0 stars 0 forks source link

Infrastructure: Module Architecture Stage 2 #81

Closed daveseah closed 9 months ago

daveseah commented 9 months ago

This stage defines a new modular code system that will be used for NetCreate 2.0 features (e.g. commenting, data processing). The intent is to create a portable system that (1) can be easily added to existing and new projects and (2) maintain the highest possible developer experience (DX) for programmers of all skill levels.

OVERVIEW OF CHANGES

There are now two build systems and three packages.

  1. The original brunch 2 build system used with NetCreate for the main root directory that works as it did before.
  2. The new URSYS core library using esbuild with its own package.json exporting @ursys/netcreate
  3. The add-on module library, also using esbuild with its own package.json, exporting @ursys/nc-addons

The new build system defines multiple "entry points" for each package.json. The new code is exported to _ur/_dist as both legacy CommonJS modules and the newer ES Modules in either nodejs or browser contexts.

The repo is also technically a "monorepo" now, which allows the root-level npm commands to handle multiple independent packages at the same time when using npm ci and npm build similar to lerna in the GEM-STEP project.

BACKGROUND INFO

This pull request (PR) establishes the seeds of systematic modular thinking by providing an initial implementation, which has two main thrusts:

  1. Offer explicit definitions of modularity with an additional emphasis on "model-first" approach to code design and its implementation. This will help developers with different backgrounds understand what the code does by discouraging spaghetti coding.

  2. Encourage and standardize the use of existing models in industry to help developers understand the conventions around common-but-complex functions in a systematic way. Topics include asynchronous programming, event handling, animation, user interface, data architecture. This will help developers by providing simple models of use for well-established tools, terminology, and practice.

We are at the very beginning of a team-wide initiative to really nail down how we will do modular programming by capturing and systemizing software concepts as they apply to our realtime projects.

This is a long-term initiative, and there will be future stages of modular architecture refinement as we try out our starting system. The system and its components will be based on the experience we've gained since 2014 working on these particular problems together.

NEXT STEPS

KNOWN ISSUES

HOW TO TEST

This PR does not add any new NetCreate features, but does have minimal integration with the existing codebase that we can test. The most important test is Confirm Netcreate Still Works (Test 1); the other tests are optional to perform but I would appreciate that they are tested.

As the build system has been modified, it's important to do a clean install.

TEST 1: CONFIRM NETCREATE STILL WORKS

  1. pull branch dev-ds/ur-modules2
  2. open the project in VSCODE through the netcreate-itest.code-workspace project file
  3. open the integrated VSCODE terminal. test that NVM detection is working in the shell prompt. It should have the text zshrc: VISUAL STUDIO CODE INTEGRATED TERMINAL DETECTED with possibly different text below. Capture a screenshot of the entire terminal window and post as a comment here (even if successful). image

Before proceeding, we want to save your settings just in case...

  1. In the same terminal: npm run clean then npm ci
  2. backup your runtime directory (this shouldn't be necessary but play it safe)
  3. note the name of the dataset that you're currently using by looking at the netcreate-config.js file in the app-config directory.
  4. rename the netcreate-config.js to old-config.js or delete the file; you will recreate it in a future step.

Now we run NetCreate

  1. Run npm ci followed by npm run dev
  2. You should see a warning that informs you that you have not set up NetCreate.
  3. Using the dataset you noted from step 6, follow the instructions to run ./nc.js
  4. The system should start as normal, recreating the netcreate-config.js file.
  5. You may see a lot of warnings during build; this is normal because NetCreate uses very old libraries in its build system but the affected packages are limited to the development environment. For a list of these packages, see #75
  6. Make sure that everything looks like it's working.
  7. Capture the information you see just before --- compilation complete ---...it should look like this (even on M1 systems): image

TEST 2: EXPLORE THE NEW SYSTEM

  1. Back at the integrated terminal, cd _ur. This is the home of the secondary build system.
  2. Check to see that there is no _dist directory in the folder. it should be grayed out because it's an ignored file.
  3. Type ./ur to execute the build system script placeholder.
  4. build messages should appear.
  5. check the _ur/_dist folder. It should now exist and include a number of .js and .map files.

Now we will test integration with the old NetCreate codebase.

  1. Switch back to the main repo directory and run NetCreate
  2. Browse to localhost:3000 in a Chromium-based browser (e.g. Chrome or Arc)
  3. Open the Javascript console, then click the init.jsx entry to see the full debug context.

Confirm this is what you see

image

  1. There are two colored rectangles labeled UR and URMOD.
  2. Note that the @client.ts filename is showing on the right. Click it.
  3. Confirm that you are seeing TypeScript source code. On line 20, the term :void appears which is not regular Javascript.
  4. There should be no errors in the console, though you may see a single warning about 'force reloading'

TEST 3: CONFIRM LINTING AND TYPE CHECKING

These are the systems that ensure developers using Visual Studio Code are not introduce issues into the code base.

  1. Back in the integrated terminal, type npm run lint
  2. You'll see a bunch of warnings in the old code base
  3. command-click on the first warning in the terminal window. This will take you directly to the file that shows the problem. We usually have this turned off for warnings like no-unused-vars which are the majority of the warnings
  4. Find the errors in nc-logic.js. These are the critical errors that we don't want in our codebase.

Now shift attention back to the Visual Studio Code editor itself

  1. Open the file app/system/datastore.js (a plain javascript file)

  2. On line 26 insert the line 'banana'...red squiggles should appear under the word, indicating an error. Hovering over the highlighted word tells you what the error is.

  3. Modify the line to read banana = banana ++ 1. the error shifts. When there are multiple errors in a file, some errors are masked until you fix them.

  4. This shows that the ESLINT vscode extension is functioning properly

  5. Open the file _ur/browser-client/env-browser.ts (a typescript file)

  6. On line 9 insert type FOO = string; followed by const test: FOO = 123;

  7. You should see test underlined in red. Hovering over the highlighted area for a second should show you ts errors as well as eslint errors.

  8. This shows that Typescript configuration is correctly installed.

  9. Open the file _ur/node-server/files.mts (a nodejs typescript module file)

  10. Confirm that the type FOO = string; const test: FOO = 123; generates the same error as the previous version.

TEST 4: HIDDEN FILES

There are several files that are now excluded from the file explorer. These files are generally things that no one should be touching, not even other developers. Here's how to find them, though:

  1. Open VSCODE Settings
  2. Click the workspace tab to show the settings saved in netcreate-itest.code-workspace
  3. Type "Files: Exclude" into the search settings bar to narrow-down the search.
  4. You should see files like .editorconfig in the list: image
  5. Alternatively you can open the netcreate-itest.code-workspace file directly, which should have this section: image

That concludes the testing of surface features in this pull request.

daveseah commented 9 months ago

TECH NOTES

These new modules are intended to function in at three contexts from a single set of source files:

  1. as an import into NetCreate to add new features
  2. (optional) as a batch processing module running in the CLI
  3. (optional) as a participant in URSYS lifecycle events (e.g. URNET)

Initial attempt to update the build system proved too difficult due to the legacy nature of the NetCreate 1.0 codebase and could have taken months. The next course of action was to add a secondary build system alongside the old such that new code to still run inside the old code without ruining the developer experience. This also helps with the plan to make our modules reusable in the future.

image

see source Whimsical Diagram for updates

Outline of Changes

Dropped features:

benloh commented 9 months ago

Reviewing...

TEST 1: CONFIRM NETCREATE STILL WORKS

  1. Confirm nvm use screenshot_1323

  2. Confirm everything works...Template Edit BUG (Ben's bug probably) -- To reproduce

    • Go to Edit Tempalte
    • Click on "Edit Node Types"
    • Click "Add row" Uncaught ReferenceErorr: f is not defined. Template.jsx:146 screenshot_1324

TEST 2: EXPLORE THE NEW SYSTEM

  1. Type ./ur -- results in an error: screenshot_1325
daveseah commented 9 months ago

Oh, that is inadvertently including some test code that I didn't think I committed yet. Good catch!

benloh commented 9 months ago

Confirmed ./ur error fixed.

All other tests passed.

daveseah commented 9 months ago

I've pushed a few refinements to detect zsh vs bash issues, but I don't think you need to retest. I've updated the testing instructions also to fill-in missing information.

benloh commented 9 months ago

Looks like the Template.jsx fix also worked. Thanks! Merge away?

daveseah commented 9 months ago

Looks like the Template.jsx fix also worked. Thanks! Merge away?

@benloh I did one final change: removed the restriction on requiring zsh, which also opened up compatible detection for linux. This means that it should work with bash OR zsh

If you could give the PR one last check to see if npm run dev works both inside VSCODE integrated terminal and also in a standalone terminal window. The output should be different in each case, but really just wanting to avoid a crash

daveseah commented 9 months ago

@benloh You don't have to retest anything else, just run npm run dev to make sure it doesn't crash.

daveseah commented 9 months ago

Updated Script for Environment Detection

Examples of the output you should be seeing (these are zsh on macos on an M1):

Running inside VSCODE opened through the provided netcreate-itest.code-workspace (these have been standard in our projects for quite some time): image

Running inside VSCODE but folder was opened directly, skipping the workspace project which has project-specific settings, in particular ensuring that certain plugins are turned off and running workspace scripts: image

Running outside of VSCODE in a regular terminal window image

The new script should on bash now as well as I am not using any (?) zsh features. Also, this should cover the case of running linux on DO as well but I haven't tested that.

daveseah commented 9 months ago

There is now also a hard stop if there is a node version mismatch. This has been there for a while but thought I would point it out: image

benloh commented 9 months ago

Confirmed: